原题地址follow the chain:http://www.pythonchallenge.com/pc/def/linkedlist.php
打开后有一张图片,点击后进入:http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345
提示下一个nothing值,然后填写nothing值,又得到一个新nothing值。。。。。。。。。。
好吧!按照惯例查看源码:urllib may help. DON'T TRY ALL NOTHINGS, since it will never end. 400 times is more than enough.
让你用urllib解决,他说400多个nothing值不可能一个一个去填。
写了个循环,其实没到400我到第272个网页,nothing值为66831时就结束了:http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=66831
访问这个网页得到:peak.html
于是下一关:http://www.pythonchallenge.com/pc/def/peak.html
源代码:
import urllib2
i=0
nexturl='http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345'
while(True):
data = urllib2.urlopen(nexturl).read()
nothing = str(data).split(' ')[5] #由于文本很规范简单提取nothing值
nexturl ='http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='+ nothing
print str(i)+' '+ nexturl
i=i+1