Skip to content

Commit 9b07e8a

Browse files
committed
IMDB Scrape
1 parent 41d3c31 commit 9b07e8a

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name" : "node-web-scrape",
3-
"version" : "0.0.0",
3+
"version" : "0.0.1",
44
"description" : "Scrape le web.",
55
"main" : "server.js",
66
"author" : "Scotch",
77
"dependencies" : {
8-
"express" : "~3.4.4",
9-
"request" : "~2.34.1",
10-
"cheerio" : "~0.13.1"
8+
"express" : "latest",
9+
"request" : "latest",
10+
"cheerio" : "latest"
1111
}
1212
}

server.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var express = require('express');
2+
var fs = require('fs');
3+
var request = require('request');
4+
var cheerio = require('cheerio');
5+
var app = express();
6+
7+
app.get('/scrape', function(req, res){
8+
// Let's scrape Anchorman 2
9+
url = 'http://www.imdb.com/title/tt1229340/';
10+
11+
request(url, function(error, response, html){
12+
if(!error){
13+
var $ = cheerio.load(html);
14+
15+
var title, release, rating;
16+
var json = { title : "", release : "", rating : ""};
17+
18+
$('.header').filter(function(){
19+
var data = $(this);
20+
title = data.children().first().text();
21+
release = data.children().last().children().text();
22+
23+
json.title = title;
24+
json.release = release;
25+
})
26+
27+
$('.star-box-giga-star').filter(function(){
28+
var data = $(this);
29+
rating = data.text();
30+
31+
json.rating = rating;
32+
})
33+
}
34+
35+
fs.writeFile('output.json', JSON.stringify(json, null, 4), function(err){
36+
console.log('File successfully written! - Check your project directory for the output.json file');
37+
})
38+
39+
res.send('Check your console!')
40+
})
41+
})
42+
43+
app.listen('8081')
44+
console.log('Magic happens on port 8081');
45+
exports = module.exports = app;

0 commit comments

Comments
 (0)