-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkscrapper.js
More file actions
49 lines (39 loc) · 1021 Bytes
/
linkscrapper.js
File metadata and controls
49 lines (39 loc) · 1021 Bytes
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
const request = require('request');
const scrapeIt = require('scrape-it');
const jsonfile = require('jsonfile');
const fs = require('fs');
let options = {
url: 'http://www.imdb.com/chart/top',
};
let data = {
// Fetch the articles
articles: {
listItem: ".titleColumn",
data: {
url: {
selector: "a",
attr: "href",
convert: function(x){
return 'http://www.imdb.com/' + x;
}
}
}
}
}
function callback(error, response, body) {
if(error) throw error;
if (!error && response.statusCode == 200) {
let page = scrapeIt.scrapeHTML(body, data);
for(let i in page.articles)
{
if(page.articles[i].title=="")
{
page.articles.splice(i, 1);
}
}
jsonfile.writeFile('links.json', page, { spaces: 2 },(err)=>{
if (err) throw err;
});
}
}
request(options,callback);