There were two games in February, with souvenirs in the top eight of the total. The first row 11th, to get the prize is no certainty. The impulse to write a script to calculate the scores of a few games, so that they know the first time can not win (embarrassing), but also a little try BeautifulSoup.
#-*-coding:utf-8-*- fromBs4ImportBeautifulSoupImportUrllibdefupdatescorelist (scorelist, url):""":p Aram scorelist::p Aram URL:: return:"""page=urllib.urlopen (URL) soup=BeautifulSoup (page) contestants= Soup.find_all (class_="Fn-ell") forPersoninchContestants:username=person.string Row= Person.parent.parent#table row for this contestantStatics = Row.find_all ('TD') Scoretag= Statics[2] Score=Int (Unicode (scoretag.string))ifUserNameinchscorelist:scorelist[username]['score'] +=score scorelist[username]['numofcontests'] + = 1Else: Scorelist[username]= {'score': Score,'numofcontests': 1}defgenerateranklist (Urllist, numofwinners):""":p Aram Urllist:url of Hihocoder Challenge Contest rank pages:p Aram Numofwinners:number of Winners:return : The first Numofwinners winners in these contests"""scorelist= {} forUrlinchurllist:updatescorelist (scorelist, url) rank= [] forUserName, personinchScorelist.items (): Rank.append ((UserName, person['score'], person['numofcontests'])) Rank.sort (CMP=LambdaP1, p2:p2[1]-p1[1]) returnRank[:numofwinners]defMain (): Urllist= [] forNuminchRange (8, 9): Urllist.append ("Http://hihocoder.com/contest/challenge%d/rank"%num) ranklist= Generateranklist (Urllist, 8) PrintU"User name Total number of entries" forPersoninchranklist:Print Personif __name__=="__main__": Main ()View Code
Python script for statistical Hihocoder Challenge results