歇了好几天,继续挑战!
第四关什么提示都没有,查看源码,有这么一句话:
<!-- 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
顺利过关:)