第4题:http://www.pythonchallenge.com/pc/def/linkedlist.php
点击图片找到链接,根据页面提醒,更改nothing找到下一个链接。。。知道结束,应该是不是数字的时候结束。
根据正则匹配nothing的值应该简单的
import urllib
import re
def next_url(p):
text=urllib.urlopen('http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=' + str(p)).read()
num=re.match('and the next nothing is ([0-9]+)',text)
if not num: print text
return num.group(1)
num=12345
for i in range(400) :num=next_url(num)
根据上面程序中间有需要自己手工更改num的值
下面一的代码和上面的差不多,但是这两个程序我都没有完整的运行结束,据说是网络的问题。
import urllib
import re
def next_url(p):
text=urllib.urlopen('http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%s' %p).read()
num=re.search('([0-9]+)',text)
if not num: print text
print text,num.group(1)
return num.group(1)
num=12345
for i in range(400) :