-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
71 lines (57 loc) · 2.32 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var fs = require('fs');
var cheerio = require('cheerio');
var request = require('request');
var superagent = require('superagent');
var topten = [{ author : '', date : '',year:'', oo : 0, xx: 0 , url:''}];
var page = 2300;
var bcontinue = true;
getSeeds = function(url){
superagent.get('http://i.jandan.net/ooxx/page-'+url)
.end(function(err,docs){
page--
if(!err){
console.log(page)
var $ = cheerio.load(docs.text)
$('.commentlist li').each(function(){
var json = { author:'', year:'', date:'', oo:0, xx:0, url:''};
var data = $(this);
json.date = data.children().eq(1).text()
json.year = json.date.substring(2, 6)
if(json.year == '2016'){
json.oo = parseInt(data.find("*[id*='cos_support']").text())
json.author = data.children().first().text()
json.xx = parseInt(data.find("*[id*='cos_unsupport']").text())
json.url = data.find('.commenttext p img').attr('src')
var lastone = topten[topten.length-1]
if(lastone.oo < json.oo){
topten.push(json)
topten.sort(function(a, b) { return b.oo - a.oo });
if(topten.length>20){
topten.pop()
}
}
}
if(json.year == '2015'){
bcontinue = false
}
})
}
if (bcontinue){
getSeeds(page)
}else{
console.log(topten)
for(var j=0;j<topten.length;j++){
var downs = topten[j]
if(downs.oo>100)
downloadImg('http:'+downs.url,downs.url.split('/')[4]);
}
}
})
};
var dir = './images';
var downloadImg = function(url, filename){
request.head(url, function(err, res, body){
request(url).pipe(fs.createWriteStream(dir + "/" + filename));
});
};
getSeeds(page)