Python实训day06pm【网络爬虫(爬取接口)-爬取图片、音频、数据;查找视频下载地址_3/3】
下午的任务:爬取各种各样的接口数据(2-3个课堂练习)
1、练习——LOL英雄头像与英雄语音
2、视频下载
3、练习——爬取腾旭实时疫情网站
课堂练习:https://news.qq.com/zt2020/page/feiyan.htm#/?nojump=1
1.爬取腾旭实时疫情网站,找到从2021年12月1日到2022年1月10日,每日新增确诊人数,存入到一个dict中;
2.找到哪一天新增确诊最多。
'''
课堂练习:
1.爬取腾旭实时疫情网站,找到从2021年12月1日到2022年1月10日,每日新增确诊人数,存入到一个dict中;
2.找到哪一天新增确诊最多。
https://news.qq.com/zt2020/page/feiyan.htm#/?nojump=1
'''
import requests;
import json;
# 通过浏览器找到接口:
url = 'https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=chinaDayAddList'
hds = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36'}
resp = requests.get(url, headers=hds);
ct = resp.content.decode('utf-8');
print(ct) # {"ret":0,"info":"","data":{"chinaDayAddList":[{"localConfirmadd":6,"date":"11.17","y":"2021","dead":0,"heal":60,
ct = json.loads(ct); # 转为json格式,ct是字典形式
ls = ct['data']['chinaDayAddList'];
print(ls) # [{'localConfirmadd': 6, 'date': '11.17', 'y': '2021', 'dead': 0, 'heal': 60, 'importedCase': 29, 'localinfectionadd': 0,
print(len(ls)) # 60
tj = {}; # 统计
for l in ls:
y = l['y'];
m = l['date']
if y + '.' + m >= '2021.12.01':
tj[y + '.' + m] = l['localConfirmadd'];
print(tj)
tj = list(tj.items()); # 转为list
tj.sort(key=lambda x: x[1], reverse=True); # 倒序,查看最大值
print(tj)




浙公网安备 33010602011771号