forked from danieljoppi/node-linkedin-scraper2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (37 loc) · 1.33 KB
/
index.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
var jsdom = require('jsdom'),
Q = require('q');
module.exports = function (originalUrl, callback) {
var deferred = Q.defer();
var profileFactory = require('./lib/profile');
var linkedInURL = originalUrl.replace(/[a-z]*\.linkedin/, 'www.linkedin');
jsdom.env({
url: linkedInURL,
scripts: ['http://code.jquery.com/jquery.js'],
headers: {
'Accept': 'text/html',
//'Accept-Encoding': 'gzip',
'Accept-Language': 'en-US;q=0.6,en;q=0.4',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36'
},
proxy: process.env.PROXY_HOST,
tunnel: process.env.PROXY_HOST ? false : undefined,
done: function (errors, window) {
if (errors) {
if (callback) {
callback(errors);
} else {
deferred.reject(errors);
}
} else {
var profile = profileFactory(window);
profile.publicProfileUrl = originalUrl;
if (callback) {
callback(null, profile);
} else {
deferred.resolve(profile);
}
}
}
});
return deferred.promise;
};