4.用到urllib和beautifulsoup
import urllib.request from bs4 import BeautifulSoup nothing='12345' for x in range(1,400): #读取页面 f = urllib.request.urlopen("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="+nothing) #获取页面HTML内容 html_doc2 = f.read() #解析HTML,获得一个SOUP对象 soup2 = BeautifulSoup(html_doc2, "html.parser") #利用.get_text()获得字符串,string.spilt()获得一个列表 list=soup2.get_text().split() #根据特性取最后一个字段,重复下载,重复400次 count=len(list) nothing=list[count-1] print(nothing)