Pychallenge (4)-follow the chain, pychallenge-follow

Source: Internet
Author: User

Pychallenge (4)-follow the chain, pychallenge-follow

Pychallenge 4th

<! -- Urllib may help. DON't try all nothings, since it will never

End. 400 times is more than enough. -->

The dot picture jumps out: and the next nothing is 44827, which looks like a nested webpage

#-*-Coding: UTF-8-*-import requestsimport reimport timeclass NothingException (Exception): def _ init _ (self, length, rtvalue): Exception. _ init _ (self) self. length = length self. rtvalue = rtvaluedef findnothing (start_noth): "": type start_noth: str: rtype nothing: str "nothing = start_noth url_prefix = 'HTTP: // required? Nothing = 'url = url_prefix + nothing try: for I in range (400): r = requests. get (url) print "now it's % d time for requesting for page: % s" % (I, url) time. sleep (1) if r. status_code = 200: nothing = re. findall ('and the next nothing is \ d +', r. content) # retrieve the target string in a fixed format if len (nothing )! = 1: raise NothingException (len (nothing), 1) # If there are more than one result, else: url = url_prefix + str (re. findall ('\ d +', nothing [0]) [0]) # normally retrieve nothing and continue to access else: print "get page % s failed" % url break failed t NothingException: print "now it's necessary for you to determine <nothing>. "print" hint is: % s "% r. content m_noth = raw_input ("please input <nothing>:") # manually determine nothing findnothing (m_noth) in non-normal words) return nothingif _ name _ = '_ main _': print findnothing ('20140901 ')

The final result is peak.html.

 

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.