import urllib.request,re
src='http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345'
url='http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='
count=0
while True:
nexturl=urllib.request.urlopen(src).read()
'''#一种方法
if str(nexturl[-5]).isdigit():
nextid=nexturl[-5:]
elif str(nexturl[-4]).isdigit():
nextid=nexturl[-4:]
else:
nextid=nexturl[-3:]
#nextid=nexturl.split('=')[-1];为什么不能切片(应先转格式nexturl=str(nexturl,encoding='utf-8'))
count+=1
try:
nextid=int(nextid)
except:
break
'''
nexturl=str(nexturl,encoding='utf-8')
if nexturl[-1].isdigit():
nextid=''.join(re.findall('[0-9]*',nexturl))
count+=1
else:
break
src=url+str(nextid)
print(count,'next url-->'+src)
09-26
09-26