-
Notifications
You must be signed in to change notification settings - Fork 0
/
app2.js
104 lines (77 loc) · 2.86 KB
/
app2.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var fs = require('fs');
var cheerio = require('cheerio');
var request = require('request');
var superagent = require('superagent');
var async = require('async');
var topten = [{ author:'', year:'', date:'', oo:0, xx:0, url:''}];
getSeeds = function(url,callback){
superagent.get('http://i.jandan.net/ooxx/page-'+url)
.end(function(err,docs){
console.log(url)
var year = '2016';
if(!err){
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)
year = json.year
if(json.year == '2016'){
json.author = data.children().first().text()
json.oo = parseInt(data.find("*[id*='cos_support']").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>10){
topten.pop()
}
}
}
})
}
if(year =='2015')
callback(true)
else
callback()
})
};
var pages = [];
for(var i=2300;i>1300;i--){
pages.push(i);
}
async.mapLimit(pages, 40,
function (page, cb) {
getSeeds(page, cb);
},
function (err, results) {
setTimeout(function () { //等一会儿,其他的页面都callback
console.log(topten)
}, 3000);
}
);
// async.whilst(
// function() {
// pages = [];
// for(var i=0; i<40; i++){
// pages.push(firstpage-i)
// }
// firstpage = firstpage-40
// return year != 2015
// },
// function(callback) {
// async.map(pages,
// function (page, cb) {
// getSeeds(page, cb);
// },
// function (err, results) {
// callback(err,results)
// }
// );
// },
// function (err, n) {
// }
// );