python实现疫情数据爬取

                         **python实现疫情数据爬取**

废话不多说,直接上代码:

import requests
import json

url = ‘https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5’#HTTP请求
data = json.loads(requests.get(url).json()[‘data’])
update_time = data[‘lastUpdateTime’]# 更新时间
China = data[‘areaTree’][0][‘children’]# 全国各地具体数据
url = ‘https://view.inews.qq.com/g2/getOnsInfo?name=disease_foreign’#HTTP请求
data = json.loads(requests.get(url).json()[‘data’])
foreign_List = data[‘foreignList’]#国外数据

total = [i[‘total’] for i in China]
ncp_info = ‘省份: {} 确诊病例: {} 现有确诊病例: {} 疑似病例: {} 死亡病例: {} 治愈病例: {} 更新日期:{}’.format(
[i[‘name’] for i in China],
[i[‘confirm’] for i in total],
[i[‘nowConfirm’] for i in total],
[i[‘suspect’] for i in total],
[i[‘dead’] for i in total],
[i[‘heal’] for i in total],
update_time
)
with open(’./temp.json’,‘w’) as f:
json.dump(ncp_info, f, ensure_ascii=False)

ncp_info1 = ‘全球国家: {} 确诊病例: {} 现有确诊病例: {} 疑似病例: {} 死亡病例: {} 治愈病例: {} 更新日期:{}’.format(
[i[‘name’] for i in foreign_List],
[i[‘confirm’] for i in foreign_List],
[i[‘nowConfirm’] for i in foreign_List],
[i[‘suspect’] for i in foreign_List],
[i[‘dead’] for i in foreign_List],
[i[‘heal’] for i in foreign_List],
update_time
)
with open(’./temp1.json’,‘w’) as f: #将数据保存为json文件
json.dump(ncp_info1, f, ensure_ascii=False)
print(ncp_info,ncp_info1)#打印查看

结果如下:
python实现疫情数据爬取_第1张图片
接下就可以对数据进行各类操作分析

你可能感兴趣的:(python,python,大数据,数据可视化)