-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
48 lines (34 loc) · 1.24 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
var express = require('express'),
fs = require('fs'),
request = require('request'),
cheerio = require('cheerio'),
app = express();
app.get('/scrape', function(req, res){
url = 'http://www.imdb.com/title/tt0421054/';
request(url, function(error, response, html){
if(!error){
var $ = cheerio.load(html);
var title, release, rating;
var json = { title : "", release : "", rating : ""};
$('.header').filter(function () {
var data = $(this);
title = data.children().first().text();
release = data.children().last().children().text();
json.title = title;
json.release = release;
});
$('.star-box-giga-star').filter(function() {
var data = $(this);
rating = data.text();
json.rating = rating;
});
}
fs.writeFile('output.json', JSON.stringify(json, null, 4), function(err){
console.log('File successfully written! - Check your project directory for the output.json file');
});
res.send('Check your console!');
});
});
app.listen('8081');
console.log('Magic happens on port 8081');
exports = module.exports = app;