疫情数据
程序源码
// An highlighted block import requests import json class epidemic_data(): def __init__(self, province): self.url = url self.header = header self.text = {} self.province = province # self.r=None def down_page(self): r = requests.get(url=url, headers=header) self.text = r.text # self.r = r def parse_page(self): # print(type(self.r.json()['data'])) # 因为解析数据为 data 前有一个"",所以数据类型为string data_str = json.loads(self.text)['data'] #sring # print(type(data_dict)) # print(type(data_dict['data'])) # 将str 转化为对象 data_json = json.loads(data_str) data_tree_dict = data_json['areaTree'][0]['children'] # 取中国的省列表 prt_str = [] prt_str.append("数据更新时间:"+data_json['lastUpdateTime']) prt_str.append("全国" + ":" + "累计确诊病例:" + str(data_json['chinaTotal']['confirm']) + "累计疑似病例:" + str(data_json['chinaTotal']['suspect']) + "累计死亡病例:" + str(data_json['chinaTotal']['dead']) + "累计出院病例:" + str(data_json['chinaTotal']['heal']) + "今日新增确诊病例:" + str(data_json['chinaAdd']['confirm']) + "今日新增疑似病例:" + str(data_json['chinaAdd']['suspect']) + "今日新增死亡病例:" + str(data_json['chinaAdd']['dead']) + "今日新增出院病例:" + str(data_json['chinaAdd']['heal'])) for province_list in data_tree_dict: for provice_name in self.province: if provice_name in province_list['name']: city_list = province_list['children'] prt_str.append(province_list['name'] + ":" + "累计确诊病例:" + str(province_list['total']['confirm']) + "累计死亡病例:" + str(province_list['total']['dead']) + "累计出院病例:" + str(province_list['total']['heal']) + "今日新增确诊病例:" + str(province_list['today']['confirm']) + "今日新增死亡病例:" + str(province_list['today']['dead']) + "今日新增出院病例:" + str(province_list['today']['heal'])) if provice_name == '山东': for data_dict in city_list: prt_str.append(data_dict['name'] + ":" + "累计确诊病例:" + str(data_dict['total']['confirm']) + "累计死亡病例:" + str(data_dict['total']['dead']) + "累计出院病例:" + str(data_dict['total']['heal']) + "今日确诊病例:" + str(data_dict['today']['confirm']) + "今日死亡病例:" + str(data_dict['today']['dead']) + "今日出院病例:" + str(data_dict['today']['heal'])) for item in prt_str: print(item) a = data_tree_dict # print(type(data_tree_dict['chinaTotal'])) # print(data_tree_dict.keys()) def write_page(self): pass def show(self): pass def show(self): self.down_page() self.parse_page() if __name__ == '__main__': url = 'https://view.inews.qq.com/g2/getOnsInfo"color: #ff0000">总结以上所述是小编给大家介绍的python 爬取疫情数据的源码,希望对大家有所帮助!
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“python 爬取疫情数据的源码”评论...
更新动态
2024年11月25日
2024年11月25日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]