-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse.js
36 lines (28 loc) · 945 Bytes
/
parse.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
const cheerio = require('cheerio');
const fs = require('fs');
let html = fs.readFileSync('test.html', 'utf-8');
const $ = cheerio.load(html, {
normalizeWhitespace: true
})
let op = [];
$('li[id^="job_listing"]').each(function (i, elm) {
op.push({
job_id: $(this).attr('id').replace('job_listing-', ''),
job_title: $(this).attr('data-title'),
job_type: $(this).find('ul.meta>li.job-type').text().trim(),
job_link: $(this).attr('data-href'),
posted_date: $(this).find('ul.meta>li.date')
.text()
.replace(/Posted|ago/gi, '')
.trim()
})
});
// console.log(op);
let jsonContent = JSON.stringify(op, null, 4);
fs.writeFile("output.json", jsonContent, 'utf8', function (err) {
if (err) {
console.log("An error occured while writing JSON Object to File.");
return console.log(err);
}
console.log("JSON file has been saved.");
});