下学期有个 个人项目,高考志愿填报系统,
需要高考不同学校不同专业的录取分数线
通过简单的网页分析,得到请求的接口,然后模拟这个过程即可
import csvimport jsonimport requestsdef save_data(data):with open('./高考志愿.csv', encoding='UTF-8', mode='a+', newline='') as f:f_csv = csv.writer(f)f_csv.writerow(data)f.close()print("#########"" 版权所有:Riand & 数据接口来源-/school/search & 在此表示感谢!""##########")header={'user-agent': '' #自己填自己的}head=['省份','学校名称','专业','最低录取分','最低录取名次','选课要求']with open('./高考志愿.csv', encoding='utf-8-sig', mode='w', newline='') as f:f_csv = csv.writer(f)f_csv.writerow(head)f.close()s1='/web/api/?admissions=¢ral=&department=&dual_class=&f211=&f985=&is_doublehigh=&is_dual_class=&keyword=&nature=&page='s2='&province_id=&ranktype=&request_type=1&school_type=&size=20&top_school_id=[589]&type=&uri=apidata/api/gk/school/lists&signsafe=429e2ced223b25d694a7a8ce81f73915's3='https://static-/www/2.0/schoolspecialindex//'s4='/33/3/16/'for i in range(1,143):url=s1+str(i)+s2html = requests.post(url,headers=header).textunicodestr = json.loads(html)dat = unicodestr["data"]dat = dat["item"]for j in dat:school = j["name"]schoolid = j["school_id"]province_name=j["province_name"]print(school)for k in range(1, 10):urll = s3 + str(schoolid) + s4 + str(k) + '.json'htmll = requests.get(urll, headers=header).textunicode = json.loads(htmll)try:da = unicode["data"]except:breakda = da["item"]for w in da:sc = w["min"]min_section = w["min_section"]spname = w["spname"]sp_info = w["sp_info"]tap = (province_name, school, spname, sc, min_section, sp_info)save_data(tap)
如果觉得《Python 爬取高考各学校各专业录取分数线》对你有帮助,请点赞、收藏,并留下你的观点哦!