-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper.js
56 lines (46 loc) · 1.86 KB
/
scraper.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
const axios = require('axios');
const cheerio = require('cheerio');
const ObjectsToCsv = require('objects-to-csv');
linkedinJobs = [];
let pageNumber = 0;
function getInfo() {
return new Promise((resolve, reject) => {
setTimeout(() => {
let url = `https://www.linkedin.com/jobs/search?keywords=Web%20Development&location=Lagos%2C%20Lagos%20State%2C%20Nigeria&geoId=105693087&trk=public_jobs_jobs-search-bar_search-submit&position=1&pageNum=0&start=${pageNumber}`;
axios(url).then(response => {
const html = response.data;
const $ = cheerio.load(html);
const jobs = $('li')
jobs.each((index, element) => {
const jobTitle = $(element).find('h3.base-search-card__title').text().trim()
const company = $(element).find('h4.base-search-card__subtitle').text().trim()
const location = $(element).find('span.job-search-card__location').text().trim()
const link = $(element).find('a.base-card__full-link').attr('href')
linkedinJobs.push({
'Title': jobTitle,
'Company': company,
'Location': location,
'Link': link,
})
if(!jobTitle || !company || !location || !link){
linkedinJobs.pop()
}
resolve(linkedinJobs)
});
// const csv = new ObjectsToCsv(linkedinJobs)
// csv.toDisk('./linkedInJobs.csv', { append: true })
})
.catch(console.error)
pageNumber+= 25;
if(pageNumber < 50){
getInfo()
}
}, 5000);
})
}
let jobs = new Promise(function showResult(resolve, reject){
getInfo().then((result) =>{
resolve(result)
}).catch(err => console.log(err))
})
module.exports = {jobs}