guoneiyiqin

import requests
from lxml import etree
from openpyxl import Workbook
import json

#1 获取数据
result =requests.get('https://voice.baidu.com/act/newpneumonia/newpneumonia')
#print(result.text)
#2解析数据
html = etree.HTML(result.text)
res = html.xpath('//script[@type="application/json"]/text()')
#print(res[0])
# print(type(res))
# print(type(res[0]))
res = json .loads(res[0])
#print(res)
#3保存
wb = Workbook()
#print(res['component'][0]['globallist'])
res = res['component'][0]['caseList']
for each in res:
print(each)
print('*'*50,'\n')
sheet_title = each['area']
ws = wb.create_sheet(sheet_title)
ws.append(['地区','累计确诊','累计死亡','累计治愈','现有确诊','新增确诊'])
#print(sheet_title)
for each in each['subList']:
print(each)
print('*' * 60, '\n')
ws.append([each['city'],each['confirmed'],each['died'],
each['crued'],each['curConfirm'],each['confirmedRelative']])

wb.save('2022527国内疫情数据.xlsx')

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值