-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrawler.js
More file actions
53 lines (44 loc) · 1.24 KB
/
Copy pathcrawler.js
File metadata and controls
53 lines (44 loc) · 1.24 KB
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
50
51
52
53
const express = require('express');
const app = express();
app.set('view engine', 'ejs');
app.set('views', 'views');
app.use(express.static('public'))
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(dados = []){
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();
//Crawler.fs.appendFile('imdb.txt', title + ' - ' + rating + '\n');
if(rating == ''){
rating = "sem avaliação"
}
var response = {title, rating}
dados.push(response)
});
app.get('/', function(req, res){
return res.render('index', {dados: dados})
})
});
}
};
Crawler.init();
app.listen(3000, (err) => {
if(err) {
console.log('==> [-] falha na aplicação');
} else {
console.log('==> [+] aplicação funcionando ');
}
});