本文主要是介绍Python爬取1000多所世界大学排名数据,制作可视化图。强不强你说了算。,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前言
QS世界大学排名(QS World University Rankings)是由英国一家国际教育市场咨询公司Quacquarelli Symonds(简称QS)所发表的年度世界大学排名
import requests # 发送请求
import re
import csvwith open('rank.csv', mode='a', encoding='utf-8', newline='') as f:csv_writer = csv.writer(f)csv_writer.writerow(['country', 'rank', 'region', 'score_1', 'score_2', 'score_3', 'score_4', 'score_5', 'score_6', 'total_score', 'stars', 'university', 'year'])
def replace(str_):str_ = re.findall('<div class="td-wrap"><div class="td-wrap-in">(.*?)</div></div>', str_)[0]return str_
url = 'https://www.qschina.cn/sites/default/files/qs-rankings-data/cn/2057712_indicators.txt'
# 1. 发送请求
response = requests.get(url)
# <Response [200]>: 请求成功
# 2. 获取数据
json_data = response.json() # Python 字典
# 3. 解析数据
# 字典
data_list = json_data['data']
for i in data_list:country = i['location'] # 国家/地区rank = i['overall_rank'] # 排名region = i['region'] # 大洲score_1 = replace(i['ind_76']) # 学术声誉score_2 = replace(i['ind_77']) # 雇主声誉score_3 = replace(i['ind_36']) # 师生比score_4 = replace(i['ind_73']) # 教员引用率score_5 = replace(i['ind_18']) # 国际教师score_6 = replace(i['ind_14']) # 国际学生total_score = replace(i['overall']) # 总分stars = i['stars'] # 星级uni = i['uni'] # 大学名称university = re.findall('<div class="td-wrap"><div class="td-wrap-in"><a href=".*?" class="uni-link">(.*?)</a></div></div>', uni)[0]year = "2021" # 年份print(country, rank, region, score_1, score_2, score_3, sco
这篇关于Python爬取1000多所世界大学排名数据,制作可视化图。强不强你说了算。的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!