Skip to content

Commit 26bb0bd

Browse files
author
curiositycasualty
committed
formatting
1 parent 40fd898 commit 26bb0bd

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

server.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
var express = require('express');
2-
var fs = require('fs');
2+
var fs = require('fs');
33
var request = require('request');
44
var cheerio = require('cheerio');
55
var app = express();
66

77
app.get('/scrape', function(req, res){
8-
// Let's scrape Anchorman 2
9-
url = 'http://www.imdb.com/title/tt1229340/';
8+
// Let's scrape Anchorman 2
9+
url = 'http://www.imdb.com/title/tt1229340/';
1010

11-
request(url, function(error, response, html){
12-
if(!error){
13-
var $ = cheerio.load(html);
11+
request(url, function(error, response, html){
12+
if(!error){
13+
var $ = cheerio.load(html);
1414

15-
var title, release, rating;
16-
var json = { title : "", release : "", rating : ""};
15+
var title, release, rating;
16+
var json = { title : "", release : "", rating : ""};
1717

18-
$('.title_wrapper').filter(function(){
19-
var data = $(this);
20-
title = data.children().first().text().trim();
21-
release = data.children().last().children().last().text().trim();
18+
$('.title_wrapper').filter(function(){
19+
var data = $(this);
20+
title = data.children().first().text().trim();
21+
release = data.children().last().children().last().text().trim();
2222

23-
json.title = title;
24-
json.release = release;
25-
})
23+
json.title = title;
24+
json.release = release;
25+
})
2626

27-
$('.ratingValue').filter(function(){
28-
var data = $(this);
29-
rating = data.text().trim();
27+
$('.ratingValue').filter(function(){
28+
var data = $(this);
29+
rating = data.text().trim();
3030

31-
json.rating = rating;
32-
})
33-
}
31+
json.rating = rating;
32+
})
33+
}
3434

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-
})
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+
})
3838

39-
res.send('Check your console!')
40-
})
39+
res.send('Check your console!')
40+
})
4141
})
4242

4343
app.listen('8081')
4444
console.log('Magic happens on port 8081');
45-
exports = module.exports = app;
45+
exports = module.exports = app;

0 commit comments

Comments
 (0)