-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob-crawler.js
executable file
·46 lines (37 loc) · 1.35 KB
/
job-crawler.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
const request = require("request");
const cheerio = require("cheerio");
const url = 'https://ca.indeed.com/Software-Developer-jobs-in-toronto';
const fs = require('fs');
var pageUrls = [];
var JobArr = [];
var index = 0;
for(var i=0 ; i<= 500 ; i+=10){
if (i == 0){
pageUrls.push(url);
} else{
pageUrls.push('https://ca.indeed.com/jobs?q=Software+Developer&l=toronto&start='+i);
}
}
pageUrls.forEach(function(pageUrl){
request(pageUrl, (err, res, html) => {
// SinglePageJob = [];
console.log(pageUrl);
const $ = cheerio.load(html);
$('div.jobsearch-SerpJobCard').each(function(i,v) {
JobArr.push({
JobTitle: $(v).find('a.jobtitle.turnstileLink').attr("title"),
Company: $(v).find(".company").text().trim(),
Location: $(v).find("div.recJobLoc").attr("data-rc-loc"),
JobSalary: $(v).find("span.salaryText").text().trim(),
JobSummary: $(v).find("div.summary").text().trim(),
PostDate: $(v).find("span.date").text().trim(),
JobLink: 'https://ca.indeed.com' + $(v).find('a.jobtitle.turnstileLink').attr("href"),
});
});
let data = JSON.stringify(JobArr, null, 2);
fs.writeFile('job.json', data, (err) => {
if (err) throw err;
console.log('Data written to file');
});
});
});