PythonChallenge 挑战之路 Level-4

歇了好几天,继续挑战!

第四关什么提示都没有,查看源码,有这么一句话:

<!-- urllib may help. DON'T TRY ALL NOTHINGS, since it will never 
end. 400 times is more than enough. -->

再返回,点击图片,转到一个新的页面: http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345

页面只有一句话:and the next nothing is 44827

结合起来题目大致的意思就是从新页面(nothing=12345)开始,用内容中给出的数字替换网址,不断重复直到结束,重复次数不会超过400次。推荐用urllib模块。


给出代码:

import urllib
import re
nothing = str(12345)
for i in range(400):
    path = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='
    text = urllib.urlopen(path+nothing).read()
    a = re.findall(r'(\d+)',text)
    print i, text    
    if a == []:
        break
    nothing = str(a[len(a)-1])
运行结束,结果是:

Yes. Divide by two and keep going.

这一步的nothing=16044,那么用8022作为初始值,再跑一遍,结果:

peak.html

顺利过关:)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值