Home > other >  For help, Python penalising Chinese university rankings are there?
For help, Python penalising Chinese university rankings are there?

Time:10-26

The import requestsfrom bs4
The import BeautifulSoupimport bs4def getHTMLText (url) :
Try:
R=requests. Get (url, timeout=30) r.r aise_for_status () r.e ncoding=state Richard armitage pparent_encoding
Return r.t ext
Except:
Return ""
Def fillUnivList (ulist, HTML) : soup=BeautifulSoup (HTML, ". The HTML parser ")
For the tr in soup. The find (' tbody.) children:
If isinstance (tr, bs4. Element. The Tag) :
TDS=tr (" td ") ulist. Append ([TDS [0], string, TDS [1]. The string, TDS [2]. The string])
Def printUnivList (ulist, num) : print (" {: ^ 10} {: ^ 6} \ \ t t {: ^ 10} ". The format (" rank ", "school name", "top"))
For I in range (num) :
U=ulist [I] print (" {: ^ 10} {: ^ 6} \ \ t t {: ^ 10} ". The format (u [0], u [1], u [2]))
Url="https://www.zuihaodaxue.com/BCSR/zhexue2019.html"

Uinfo=[]
HTML=getHTMLText (url)
FillUnivList (uinfo, HTML)
PrintUnivList before (20) uinfo, # 20 universities
  • Related