forked from diogocezar/dctb-node-crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrawler.js
More file actions
29 lines (28 loc) · 885 Bytes
/
crawler.js
File metadata and controls
29 lines (28 loc) · 885 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
var Crawler = {
request : null,
cheerio : null,
fs : null,
init : function(){
Crawler.request = require('request');
Crawler.cheerio = require('cheerio');
Crawler.fs = require('fs');
Crawler.getMovies();
},
getMovies: function(){
Crawler.request('http://www.imdb.com/chart/moviemeter', function(err, res, body){
if(err)
console.log('Error: ' + err);
var $ = Crawler.cheerio.load(body);
$('.lister-list tr').each(function(){
var title = $(this).find('.titleColumn a').text().trim();
var rating = $(this).find('.imdbRating strong').text().trim();
console.log(title + ' - ' + rating);
Crawler.fs.appendFile('imdb.txt', title + ' - ' + rating + '\n');
Crawler.fs.appendFile('imdb.txt', title + ' - ' + rating + '\n', (err) => {
if (err) console.log('Erro: ' + err);
});
});
});
}
};
Crawler.init();