先贴代码吧。
from urllib import *
import re
import os
src = urlopen(r'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345')
nexturl = None
url = r'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='
lasturl = r'http://www.pythonchallenge.com/pc/def/'
log = open(r'E:\log.log','a')
while True:
nexturl = src.readline()
nextid = nexturl[-5:]
try:
nextid = int(nextid)
except:
print('exit#:'+nexturl)
os.startfile(lasturl+nexturl)
break
nexturl = url+str(nextid)
log.write('next url-->'+nexturl)
print('next url-->'+nexturl)
src.close()
src = urlopen(nexturl)
题目要求不断地用新网页中的数字替换url中的数字所以..
运行的很慢,最后是这个结果:http://www.pythonchallenge.com/pc/def/peak.html