-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimdb.js
47 lines (38 loc) · 1.4 KB
/
imdb.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
var cheerio = require('cheerio');
var express = require('express');
var fs = require('fs');
var request = require('request');
var app = express();
app.get('/scrape', function(req, res){
//could increment on ID to pull more movies
var url = 'http://www.imdb.com/title/tt1229340/';
request(url, function(err, response, html){
if(!err){
var $ = cheerio.load(html, {normalizeWhitespace: true});
var title, release, rating;
var json = {title : '', release : '', rating : ''};
$('.title_wrapper').filter(function(){
var data = $(this);
title = data.children().first().text();
json.title = title.trim();
});
$('.titleYear').filter(function(){
var data = $(this);
release = data.text();
json.release = release;
});
$('.ratingValue').filter(function(){
var data = $(this);
rating = data.children().first().text();
json.rating = rating;
});
}
fs.writeFile('imdbOut.json', JSON.stringify(json, null, 4), function(err){
console.log('data written to imdbOut.json');
});
res.send('check your terminal');
});
});
app.listen('8081');
console.log('listening on port 8081');
exports = module.exports = app;