本文的文字及圖片來源于網路,僅供學習、交流使用,不具有任何商業用途,著作權歸原作者所有,如有問題請及時聯系我們以作處理
以下文章來源于云邊鎮 ,作者花花
前言
軟科世界大學學術排名(ShanghaiRanking’s Academic Ranking of World Universities,簡稱ARWU)于2003年由上海交通大學世界一流大學研究中心首次發布,是世界范圍內首個綜合性的全球大學排名,2009年開始由軟科發布并保留所有權利,軟科世界大學學術排名是全球最具影響力和權威性的大學排名之一,在世界各地被廣泛報導和大量參考,許多國家的政府和大學以ARWU為標準,制定戰略目標和發展規劃,采取各種舉措來提升大學的國際競爭力,軟科世界大學學術排名以評價方法的客觀、透明和穩定著稱,全部采用國際可比的客觀指標和第三方資料,包括獲諾貝爾獎和菲爾茲獎的校友和教師數、高被引科學家數、在《Nature》和《Science》上發表的論文數、被SCIE和SSCI收錄的論文數、師均學術表現等(查看排名方法),軟科世界大學學術排名每年排名的全球大學超過2000所,發布最為領先的前1000所大學,
查看網頁源代碼
查看文本檔案中的HTML資訊
開發環境
- Python 3.8
- Spyder
爬取資料
#爬取軟科世界大學學術排名 import requests from bs4 import BeautifulSoup if __name__ == "__main__": destinationPath = "html資訊.txt" allUniv = [] # headers={'User-Agent':'Mozilla/5.0'} url= 'https://www.shanghairanking.cn/rankings/arwu/2020' try: r = requests.get(url=url, timeout=30) r.raise_for_status() r.encoding = 'utf-8' html = r.text except: html = "" # fd = open(destinationPath,"w+") # 注意這里會報錯:UnicodeEncodeError: 'gbk' codec can't encode character '\xa9' in position 0: illegal multibyte sequence fd = open(destinationPath,"w+",encoding='utf-8') fd.writelines(html) fd.close() # print(html) # 注意在vscode下這里列印不全,故將結果保存在檔案中 soup = BeautifulSoup(html, "html.parser") # fillUnivList(soup) # printUnivList(10) print("{0:{5}<10}{1:{5}^10}{2:{5}^12}{3:{5}^10}{4:{5}^10}".format("排名","學校名稱","國家","排名","總分",(chr(12288)))) data = soup.find_all('tr') for tr in data: # 每一行,對應每一個學校 ltd = tr.find_all('td') if len(ltd)==0: continue singleUniv = [] # UniName = tr.find('a') # singleUniv = [UniName.string] for td in ltd: if td.find("a"): UniName = td.find("a").string singleUniv.append(UniName) elif td.string.strip(): singleUniv.append(td.string.strip()) allUniv.append(singleUniv) # print(singleUniv) # num = len(allUniv) num = 30 for i in range(num): u=allUniv[i] print("{0:<10}{1:{5}^20}{2:{5}<10}{3:{5}^4}{4:^33}".format(u[0],u[1],u[2],u[3],u[4],(chr(12288))))#排版原因,實為一行 print("{0:{5}<10}{1:{5}^10}{2:{5}^12}{3:{5}^10}{4:{5}^10}".format("排名","學校名稱","國家","排名","總分",(chr(12288))))
爬取結果
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/195940.html
標籤:Python
