-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkedinLeads.js
117 lines (111 loc) · 3.1 KB
/
linkedinLeads.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
114
115
116
117
const scrapeIt = require("scrape-it");
const { postDataToAppsScript } = require("./utils");
const { axiosProxyRequest, axiosProxyRequest1 } = require("./utils");
// Promise interface
async function scrapeData(
link = `http://www.bing.com/search?q=site%3alinkedin.com+intitle%3aDevelopment+AND+owner+AND+Chicago&qs=n&first=0`, // whole query from
results = [],
location = "Chicago",
vertical = "Development",
count,
scriptUrl,
proxyIp,
userStartTime
) {
return await axiosProxyRequest1(proxyIp, link)
.then(async resp => {
let html = resp.data;
let data = scrapeIt.scrapeHTML(html, {
// Fetch the articles
articles: {
listItem: ".b_algo",
data: {
// Get the title
name: "a",
// Nested list
link: "cite",
snippet: ".b_caption > p",
// Get the content
title: {
selector: ".b_vlist2col > ul:first-child li:first-child",
how: "text"
},
connections: {
selector: ".b_vlist2col > ul:first-child li:nth-child(2)",
how: "text"
},
industry: {
selector: ".b_vlist2col > ul:nth-child(2) li:first-child",
how: "text"
},
location: {
selector: ".b_vlist2col > ul:nth-child(2) li:nth-child(2)",
how: "text"
}
}
},
// Fetch some other data from the page
nextPage: {
selector: ".sb_pagN",
attr: "href"
},
count: {
selector: ".sb_count",
convert: x => (x.includes("Of") ? x.split("Of")[1] : x)
}
});
console.log("DATA FROM LINKEDIN", data);
let newData = [...results, ...data.articles];
console.log("NEXT PAGE DATA ", data.nextPage, link);
let countNextPage = data.nextPage
? data.nextPage
.toString()
.split("&first=")[1]
.split("&FORM=")[0]
: null;
let oldCountNextPage = link
.toString()
.split("&first=")[1]
.split("&FORM=")[0];
console.log(
"count next page",
countNextPage,
"old count next page",
oldCountNextPage
);
if (
data.nextPage !== "" &&
parseInt(countNextPage) > parseInt(oldCountNextPage) &&
count > 0
) {
setTimeout(
scrapeData(
"http://www.bing.com" + data.nextPage,
newData,
location,
vertical,
count - 1,
scriptUrl,
proxyIp,
userStartTime
),
2000
);
} else {
console.log("RESULTS", results);
await postDataToAppsScript(
scriptUrl,
results.length === 0 && newData.length ? newData : results,
"linkedin"
);
}
return html;
})
.catch(err => "");
}
function stripSpecalChar(str) {
return str.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, " ");
}
module.exports = {
linkedinLeads: scrapeData
};