-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseJobs.js
48 lines (38 loc) · 1.36 KB
/
parseJobs.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
var HTMLParser = require('node-html-parser');
var request = require('request');
module.exports = {
parseResponse: async function(body,url){
var root = HTMLParser.parse(body);
var listJobs = root.querySelectorAll('h3');
var finalData = [];
for (let index = 1; index < listJobs.length; index++) {
const element = listJobs[index];
try {
var result = await this.parseJobs(element,url);
finalData.push(result)
} catch (error) {
console.log(error.message);
continue;
}
}
return finalData;
},
parseJobs: async function(element,url){
var data = {
link : url + element.querySelectorAll('a')[0]?.rawAttributes.href.replace('/jobs',''),
title : title = element.querySelectorAll('span')[0]?.text
};
return data;
},
downloadPage: async function (url) {
return new Promise((resolve, reject) => {
request(url, (error, response, body) => {
if (error) reject(error);
if (response.statusCode != 200) {
reject('Invalid status code <' + response.statusCode + '>');
}
resolve(body);
});
});
},
};