jupyter笔记本
交互性强,可以代码块执行
网站:实时更新:新冠肺炎疫情最新动态
#导入库
import time
import json
import requests
import pandas as pd
time.time() #时间戳
html = requests.get(url)
html.text
data = json.loads(html.json()['data']) #类型转换
data
data = json.loads(html.json()['data']) #类型转换
china_data = data['statisGradeCityDetail']
data_set = []
for i in china_data:
data_dict={}
#地区名称
data_dict['city']=i['city']
#疫情数据
#新增确诊
data_dict['nowConfirm']=i['nowConfirm']
data_dict['confirmAdd']=i['confirmAdd']
data_dict['confirm']=i['confirm']
data_dict['heal']=i['heal']
data_dict['dead']=i['dead']
data_set.append(data_dict)
df = pd.DataFrame(data_set)
df
##4. 保存数据
df.to_csv(r'G:\国内疫情数据.csv',encoding='utf-8-sig')