-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
57 lines (43 loc) · 1.47 KB
/
server.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var express = require('express');
var fs = require('fs');
var request = require('request');
var cheerio = require('cheerio');
var app = express();
app.get('/scrape', function(req, res){
//url = 'https://www.imdb.com/title/tt3756788/';
url = process.argv[2];
request(url, function(error, response, html){
if(!error){
// The cheerio library gives us jquery functionalities
var $ = cheerio.load(html);
var json = { title : "", release : "", rating : ""};
$('meta').filter(function(){
var data = $(this);
if(data.attr('property') === 'og:title'){
json.title = data.attr('content');
console.log(json.title);
}
})
$('a').filter(function(){
var data = $(this);
if(data.attr('title') === 'See more release dates'){
json.release = data.text().trim();
console.log(json.release);
}
})
$('span').filter(function(){
var data = $(this);
if (data.attr('itemprop')==='ratingValue'){
json.rating = data.text();
console.log(json.rating);
}
})
}else{
console.log("error");
}
})
res.send('Check your console!\n');
})
app.listen('8081')
console.log('Listening on port 8081');
//module.exports = app;