37,719
社区成员
发帖
与我相关
我的任务
分享
import urllib.request
import re
url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345' #作为最初的url
def visit(url):
Request = urllib.request.urlopen(url)
html = Request.read().decode('utf-8')
Request.close()
Purl = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=' #把url看作为前面一部分不变的字符串加上后面的数字组成的字符串
code = str(re.findall(r'(\d+$){1}',html)) #匹配最后的数字作为code和Purl组成新的url
print('%s'%code) #测试获得的code
url = Purl+code
visit(url) #将新的url带入函数继续
return None
visit(url)
#code = str(re.findall(r'(\d+$){1}',html))
code = str(re.findall(r'(\d+$){1}',html)[0])