需要的库有requests、BeautifulSoup
import requests
from bs4 import BeautifulSoup
import bs4
uinfo = []
ulist = []
try:
r = requests.get("http://www.zuihaodaxue.com/zuihaodaxuepaiming2018.html",timeout = 30)
r.raise_for_status()
r.encoding = r.apparent_encoding
except:
r.text = ""
demo = r.text
soup = BeautifulSoup(demo,"html.parser")
for tr in soup.find('tbody').children:
if isinstance(tr,bs4.element.Tag):
tds = tr('td')
ulist.append([tds[0].string,tds[1].string,tds[2].string,tds[3].string,tds[4].string])
tplp = "{0:^10}\t{1:{3}^14}\t{2:^4}"
print( "{0:^10}\t{1:{3}^10}\t{2:^10}".format("排名","大学名字","分数",chr(12288)))
for i in range(516):
u = ulist[i]
print(tplp.format(u[0],u[1],u[3],chr(12288)))
print("Success")
![](https://i-blog.csdnimg.cn/blog_migrate/e01d78cd575fa82a1a8bd2ff098ba5ec.png)