http://www.pythonchallenge.com/pc/def/linkedlist.php
The picture is as follows:
Analysis of the problem: through the page source code parsing, to open the link http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345, and then get nothing value, Keep looping until the answer is reached.
Problem Solving Process:
From urllib import Request,parseimport Reurl = R ' http://www.pythonchallenge.com/pc/def/linkedlist.php? ' headers = {' user-agent ': R ' mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) ' R ' chrome/45.0.2454.85 safari/537.36 115browser/6.0.3 ', ' Connection ': ' keep-alive '}data = {}data[' nothing '] = "12345" def getnothing (url,data,headers): data = Parse.urlencod E (data) URL = URL + data req = Request. Request (url,headers=headers) page = Request.urlopen (req). Read (). Decode (' Utf-8 ') return pagefor I in range (251): H Tmlstr = getnothing (url=url,data=data,headers=headers) pattern = re.compile (' \d+ ') Nothingnum = Re.findall (pattern,h TMLSTR) If nothingnum:data[' nothing '] = nothingnum[0] If Len (nothingnum) >1:data[' Nothing ' ] = nothingnum[1] else:data[' nothing ' = str (int (data[' nothing ')/2) print (str (i) + "----" + htmlstr) p Rint (data[' nothing ')
Answer:
----peak.html
Experience: In the 85th and 140th time, there is a small pit
----Yes. Divide by and keep going ..... ----There maybe misleading numbers in the text. One example is 82683. Look on the next nothing and the next nothing is 63579
The process of using Python 3.x to pythonchallenge-----4