The process of using Python 3.x to pythonchallenge-----4

Source: Internet
Author: User

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

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.