Python pick up the Hundred Treasure Color website Jiangxi Fast Three when the date number and lottery results

Source: Internet
Author: User

First, the environment

Windows10+python27

Second, demand:

1, to obtain the Hundred Treasure Color website, Jiangxi Fast Three day's lottery period number and the winning number;

2, according to the input period number, the output lottery number;

Three, the code

1 #!/bin/env python2 #Coding=utf-83 4 ImportUrllib25 Import Time6 ImportRe7 8 9 classgetk3issue:Ten     """ One Get the Jackpot website fast three date entered the issue number A     """ -     def __init__(Self, url=0, page=0, sys_time=0): -         """ the Initialize Parameters -         """ -Self.url =URL -Self.page =page +Self.sys_time =Sys_time -  +     defget_url_page (self): A         """ at Get page return element -         """ -Self.sys_time = Time.strftime ('%y-%m-%d', Time.localtime (Time.time ())) -Self.url ='http://www.baibaocp.com/ks/history/lotid/10412/date/%s'%Self.sys_time -Self.page = Urllib2.urlopen (Self.url). Read (). Decode ('UTF8') -         returnSelf.page in  -     defget_issue (self): to         """ + Draw the lottery period number from the page return element -         """ theIssue_list = [] *page =self.get_url_page () $RE = re.compile (ur'<tr num=\ ' \d{9}')Panax NotoginsengElement_list =Re.findall (Re, page) -          forElementinchelement_list: theIssue = STR (element[9:18]) + Issue_list.append (issue) A         returnlist (issue_list) the  +     defget_winning_numbers (self): -         """ $ get the draw number from the page return element $         """ -Numbers_list = [] -Group_numbers_list = [] thepage =self.get_url_page () -RE = re.compile (ur"class= ' history_drawnumber ' ><span>.*</span>")WuyiElement_numbers_list =Re.findall (Re, page) theList_a =Str (element_numbers_list) -RE2 = re.compile (ur'\d{1}</span>') WuNumbers_str =Re.findall (RE2, list_a) -          forDangezhiinchNumbers_str: AboutNumbers =Dangezhi[0] $ numbers_list.append (Numbers) -  -i =0 -          whileTrue: Aj = i + 3 +Winning_numbers =Numbers_list[i:j] thei =J -             ifJ >= Len (numbers_list) +3: $                  Break the group_numbers_list.append (winning_numbers) the         returngroup_numbers_list the  the     defresult_dict (self): -         """ in Merge period number and draw number list, return to dictionary the         """ theIssue = Self.get_issue ().__iter__() Aboutresult =dict (Zip (issue, self.get_winning_numbers ())) the         returnresult the  the     defget_issue_by_dict (self): +         """ - Find a lottery number by entering a period number the         """BayiInput_issue = str (raw_input (U'Please enter the number of the issue you want to query:')) theResult_list =self.result_dict () the         ifInput_issueinchresult_list: -Number =Result_list[input_issue] -             Print 'today's%s lottery results are:%s'%(input_issue, number) the         Else: the             Print 'input period number is wrong!!! ' the  the if __name__=='__main__': -Run =getk3issue () theRun.get_issue_by_dict ()

Python pick up the Hundred Treasure Color website Jiangxi Fast Three when the date number and lottery results

Related Article

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.