im
port requests
from bs4 im
port BeautifulSoup
im
port bs4
def getHTMLText(url):
try:
r = requests.get(url, timeout=30)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text
except:
return ""
def fillUnivList(ulist, html):
soup = BeautifulSoup(html, "html.parser")
for a in soup.find(
'tbody
').children:
if isinstance(a, bs4.element.Tag):
tds = a(
'td
')
ulist.append([tds[0].string, tds[1].string, tds[2].string, tds[3].string])
def printUnivList(ulist, num):
print("{:^10} {:^6} {:^6} {:^16}".format("排名","学校名称","地区","总分"))
for i in range(num):
u=ulist[i]