首页 > 编程语言 > 详细

pythonchallenge闯关 第4题

时间:2017-10-01 12:09:08      阅读:293      评论:0      收藏:0      [点我收藏+]

4、Hint:(1)urllib可能会有帮助。不要尝试一直循环,停不下来。400次就已经足够了

     (2)www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345

进入链接之后会提示下一个nothing=的值

用urllib库和re库 类似于爬虫

技术分享
# -*- coding:UTF-8 -*-

from urllib import request
import re

def findURL(x):
    while x.isdigit():
        url = http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=+x
        print(url)
        response = request.urlopen(url)
        html = response.read()
        html = html.decode(utf-8)
        print(html)
        replacetext = re.findall(r[0-9], str(html))
        print(replacetext)
        x = "".join(replacetext)
    return html

if __name__ == __main__:
    findURL(12345)
    findURL(8022)
(4)

中间会有一个页面内容是:Yes. Divide by two and keep going.

只好包装成函数然后再继续运行

最后答案是peak.html

pythonchallenge闯关 第4题

原文:http://www.cnblogs.com/Zzzml/p/7616820.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!