Last active
January 6, 2017 07:26
-
-
Save MacLeek/3aa1b2f47b53a1d5127e3660401944f9 to your computer and use it in GitHub Desktop.
V2_THANKS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Urls = function(startUrl){ | |
this.startUrl = startUrl; | |
this.page = 0; | |
this.homePage = ''; | |
this.heartsSent = 0; | |
this.heartsRecv = 0; | |
} | |
Urls.prototype.crawl = function(year){ | |
var self = this; | |
var url = this.startUrl + this.page; | |
var end = false; | |
$.get(url, function(data, status){ | |
self.page += 1 | |
self.homePage = $(data); | |
if(year == undefined){ | |
self.heartsRecv += self.homePage.find('.data tr td:nth-child(2):contains("收到谢意")').length; | |
self.heartsSent += self.homePage.find('.data tr td:nth-child(2):contains("发送谢意")').length; | |
end = self.homePage.find('.normal_page_right').first().hasClass('disable_now'); | |
} else { | |
self.homePage.find('.data tr').each(function(i){ | |
var tr = $(this); | |
var mDate = new Date(tr.find('td:nth-child(1)').text()); | |
end = mDate < new Date(year+'-01-01'); | |
if(!end && new Date(year+1+'-01-01') > mDate ){ | |
self.heartsRecv += tr.find('td:nth-child(2):contains("收到谢意")').length; | |
self.heartsSent += tr.find('td:nth-child(2):contains("发送谢意")').length; | |
} | |
}); | |
} | |
console.log('第'+self.page+'页'); | |
if(!end){ | |
self.crawl(year); | |
} else { | |
console.log('共收到谢意:'+self.heartsRecv); | |
console.log('共发送谢意:'+self.heartsSent); | |
} | |
}); | |
} | |
new Urls('https://www.v2ex.com/balance?p=').crawl(2016); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment