Python script for statistical Hihocoder Challenge results

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.