|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 dlnb526 于 2020-2-12 16:07 编辑
由版主 zltzlt 的帖子启发
阔以单独查询各省份数据
- # -*- coding: utf-8 -*-
- """
- Created on Tue Feb 4 21:13:49 2020
- @author: dlnb5
- """
- # -*- coding: utf-8 -*-
- """
- Created on Tue Feb 4 16:28:14 2020
- @author: Vembo Liu
- """
- #爬取各个省份肺炎数据。初学的小萌新粗糙制作,就不泡菜方法了
- #武汉加油!
- #由版主 zltzlt 的帖子启发
- from requests import get
- from json import loads
- print('欢迎查询新型肺炎情况,勤洗手戴口罩勿恐慌。\n正在载入数据……')
- content = loads(get("https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5").json()["data"])
- refreshTime = content["lastUpdateTime"]
- print('数据最近更新时间是:',refreshTime)
- content1 = content["areaTree"][0]["children"]
- dict1 = {}
- count = 0
- for i in content1:
- name1 =i['name']
- dict2 ={name1:count}
- dict1.update(dict2)
- count=count+1
- while True:
- try:
- getPro = input('请输入您要查询的省份(输入1查看省份列表,输入2退出程序):')
- if getPro == '1':
- for each in dict1:
- print(each)
- getPro = input('请输入您要查询的省份:')
- if getPro == '2':
- break
-
- content2 = content1[dict1[getPro]]
- proName = content2['name']
- print('-------%s 的数据如下-----'%proName)
-
-
- total = content2['total']
- today = content2['today']
- print('总计情况: 确诊%d 疑似%d 死亡%d 治愈%d'%(total['confirm'],total['suspect'],total['dead'],total['heal']))
- print('今日新增: 确诊%d 疑似%d 死亡%d 治愈%d'%(today['confirm'],today['suspect'],today['dead'],today['heal']))
-
- #进入到二级行政区域
- content3 = content2['children']
- num1 = len(content3)
- print('共查询到%d个下辖行政区域'%num1)
-
-
- for shi in content3:
- print('------------------------------------------------')
- print(shi['name'])
- total = shi['total']
- today = shi['today']
- print('总计情况: 确诊%d 疑似%d 死亡%d 治愈%d'%(total['confirm'],total['suspect'],total['dead'],total['heal']))
- print('今日新增: 确诊%d 疑似%d 死亡%d 治愈%d'%(today['confirm'],today['suspect'],today['dead'],today['heal']))
- except:
- print('出错啦请重新输入')
复制代码
需要安装requests模块哦!!
打包后程序下载:
蓝奏云:https://www.lanzous.com/b00z8718f
密码:ea4f
感谢您的回帖及评分! |
评分
-
查看全部评分
|