-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
36 lines (30 loc) · 846 Bytes
/
app.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
var express = require('express');
var cheerio = require('cheerio');
var request = require('request');
var fs = require('fs');
var app = express();
urls = [];
request('http://www.reddit.com',function(err,resp,body){
if(!err && resp.statusCode == 200){
var $ =cheerio.load(body);
// vs (html)
$('a.title','#siteTable').each(function(){
var url = $(this).attr('href');
if(url.indexOf('i.imgur.com')!=-1){
urls.push(url);
}
});
console.log(urls);
for(var i =0; i<urls.length;i++){
request(urls[i]).pipe(fs.createWriteStream('img/' + i + '.jpg'));
}
}
});
app.set('view engine', 'jade');
app.set('views', __dirname + '/views');
app.get('/', function(req, res) {
res.render('index');
});
var server = app.listen(5787, function() {
console.log('Express server listening on port ' + server.address().port);
});