import requests from bs4 import BeautifulSoup import bs4 info=[] url ="http://www.zuihaodaxue.com/zuihaodaxuepaiming2018.html" try: r=requests.get(url,timeout=100) r.raise_for_status() r.encouding=r.apparent_encoding soup=BeautifulSoup(r.text,"html.parser") for tr in soup.find("tbody").children: if isinstance(tr,bs4.element.Tag): tds=tr.find_all("td") info.append([tds[0].string,tds[1].string,tds[3].string]) print("{0:^10}\t{1:{3}^10}\t{2}".format("排名","学校名称","总分",chr(12288))) for i in range(100): print("{0:^10}\t{1:^10}\t{2:^10}".format(info[i][0],info[i][1],info[i][2],chr(12288))) except Exception as e: print(e)