Webリンク:
http://www.zuihaodaxue.cn/zuihaodaxuepaiming2016.html
効果:
#コーディング= UTF- 8 のインポート要求 からBS4輸入BeautifulSoupの 輸入BS4 getHTML(URL)DEF: 試す: R =要求。取得(URL、タイムアウト= 30 )#获取请求 r.raise_for_status#请求状态 r.encoding = r.apparent_encoding#编码 返しr.text 除い: リターン "" DEF getUnlist(unifo、HTML): スープ = BeautifulSoup(HTML、" html.parser " ) のための TR で soup.find(" TBODY').Find_all(' TR ' ):すべてのTR TBODYの中に見出さ# TDS = tr.find_all(' TD 」) unifo.append([TDS [ 0 ] 文字列、TDS [ 1 ] 文字列、TDS [ 3 ] 。文字列]) DEF printUnlist(unifo、NUM): TPLT = " {0:10} ^ \ T {1:^ {15} 3。} \ {2 T 10} ^ " 印刷(tplt.format(" ランク"、" 大学名"、" スコア"、CHR(12288)))#用中文字符补全 用 I で:範囲(NUM) T = unifo [i]は 、印刷(tplt.format(T [ 0 ]、T [ 1 ]、T [ 2 ]、CHR(12288 ))) DEFメイン(): URL = " http://www.zuihaodaxue.cn/zuihaodaxuepaiming2016.html " HTML = getHTML(URL) unifo = [] getUnlist(unifo、HTML) printUnlist(unifo、20 ) メイン()