forked from LouisLoode/scrap-cheerio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrap.js
37 lines (29 loc) · 856 Bytes
/
scrap.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
const cheerio = require ('cheerio');
const fetchUrl = require('fetch').fetchUrl;
const iconv = require('iconv-lite');
const fs = require('fs');
const url = 'http://www.cinema-francais.fr/monteurs.htm';
// source file is iso-8859-15 but it is converted to utf-8 automatically
fetchUrl(url, function(error, meta, body){
const $ = cheerio.load(body.toString().replace(/[\n\t\r]/g, ''));
let list = []
$('b > a').filter(function(){
let data = $(this);
let words = data.text().split(' ');
let json = {
firstname : words[0],
lastname : words[1],
}
list.push(json)
})
console.log(JSON.stringify(list));
fs.writeFile(
'./data.json',
JSON.stringify(list, null, 2),
function (err) {
if (err) {
console.error('Crap happens');
}
}
);
});