-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedin-old.js
113 lines (102 loc) · 3.87 KB
/
linkedin-old.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const session_key = process.env.LINKEDIN_EMAIL
const session_password = process.env.LINKEDIN_PASSWORD
const jsdom = require("jsdom");
const JSDOM = jsdom.JSDOM;
const jsdomOptions = {
includeNodeLocations: true,
'userAgent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
runScripts: "dangerously",
cookiejar: new jsdom.CookieJar()
}
jsdomOptions.cookiejar.rejectPublicSuffixes = true
const request = require('request-promise').defaults({
jar: require('request-promise').jar(
jsdomOptions.cookiejar.store,
{rejectPublicSuffixes: true, enableLooseMode:true}
)
});
const loginGetForm = () => JSDOM.fromURL("https://www.linkedin.com/", jsdomOptions).then((dom) => {
const loginCsrfParam = dom.window.document.querySelector("#loginCsrfParam-login").value
const form = {session_key, session_password, isJsEnabled: true, loginCsrfParam}
return form
},
(err) => console.log('not heres')
)
const loginPost = (form) => {
return request.post({url: "https://www.linkedin.com/uas/login-submit", form, followAllRedirects: true})
}
loginGetForm().then(loginPost).then((results) => {
console.log(results)
})
/*
const loginCookieJar = (cookies, url="https://www.linkedin.com/uas/login-submit") => {
let j = request.jar();
cookies.split('; ').forEach((cookie) => {
j.setCookie(request.cookie(cookie), url);
})
return j
}
*/
const loginPostOld = (cookies, loginCsrfParam, session_key = username, session_password = password, isJsEnabled = false) => new Promise((res, rej) =>{
const url = "https://www.linkedin.com/uas/login-submit"
const form = {session_key, session_password, isJsEnabled, loginCsrfParam}
//const jar = loginCookieJar(cookies)
//request.post({url, jar, form, followAllRedirects: true}).then((page) => {
request.post({url, form, followAllRedirects: true}).then((page) => {
res({form, page})
}, (err) => {
rej(err)
})
})
const loginOld = () => JSDOM.fromURL("https://www.linkedin.com/", jsdomOptions).then((dom) => {
//const cookies = dom.window.document.cookie
const csrf = dom.window.document.querySelector("#loginCsrfParam-login").value
//return loginPost(cookies, csrf).then((results) => {
return loginPost({}, csrf).then((results) => {
//jsdomOptions.cookieJar = new jsdom.CookieJar(results.jar.store, {rejectPublicSuffixes: false});
//console.log(results.jar)
return results
}, (err) => {
console.log(err)
})
}, (err) => {
console.log('err')
});
const getCompanyPage = (url) => JSDOM.fromURL(url, jsdomOptions).then((dom) => {
//console.log(dom.serialize())
}, (err) => {
//console.log(err)
})
//login().then(() => getCompanyPage("https://www.linkedin.com/company/wusinich-brogan-&-stanzione"))
const linkedinLogin = () => {
const JSDOM = jsdom.JSDOM;
//var cookiejar = new tough.CookieJar();
//cookiejar.synchronous = true
const store = new tough.Store
store.synchronous = true
request = request.defaults({ jar : request.jar(store) })
const jsdomOptions = {
includeNodeLocations: true,
'userAgent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
runScripts: "dangerously",
cookiejar: new jsdom.CookieJar(store, {rejectPublicSuffixes: false, looseMode: true})
}
JSDOM.fromURL("https://www.linkedin.com/", jsdomOptions)
.then(
(dom) => {
const loginCsrfParam = dom.window.document.querySelector("#loginCsrfParam-login").value
const form = {session_key, session_password, isJsEnabled: true, loginCsrfParam}
return form
},
(err) => console.log('not heres')
).then(
(form) => request.post({url: "https://www.linkedin.com/uas/login-submit", form, followAllRedirects: true}),
(err) => console.log('error here')
).then(
(results) => {
console.log('success')
}, (err) => {
console.log(err)
}
)
}