parent
9cef8b278c
commit
44ad4862ae
@ -0,0 +1,94 @@
|
||||
import requests
|
||||
import re
|
||||
import time
|
||||
from bs4 import BeautifulSoup
|
||||
import lxml
|
||||
import json
|
||||
|
||||
class summary_cn:
|
||||
def __init__(self):
|
||||
self.confirmed = 0
|
||||
self.died = 0
|
||||
self.cured = 0
|
||||
self.asymptomatic = 0
|
||||
self.asymptomaticRelative = 0
|
||||
self.unconfirmed = 0
|
||||
self.relativeTime = 0
|
||||
self.confirmedRelative = 0
|
||||
self.unconfirmedRelative = 0
|
||||
self.curedRelative = 0
|
||||
self.diedRelative = 0
|
||||
self.icu = 0
|
||||
self.icuRelative = 0
|
||||
self.overseasInput = 0
|
||||
self.unOverseasInputCumulative = 0
|
||||
self.overseasInputRelative = 0
|
||||
self.unOverseasInputNewAdd = 0
|
||||
self.curConfirm = 0
|
||||
self.curConfirmRelative = 0
|
||||
self.icuDisable = 0
|
||||
self.mapLastUpdatedTime=0
|
||||
def __str__(self):
|
||||
string = '截止' + self.mapLastUpdatedTime+'\n'
|
||||
string+= "国内现有\n\t确诊:" + str(self.curConfirm) + '\t较昨日' + str(self.curConfirmRelative)
|
||||
string+="\n\t无症状:" + str(self.asymptomatic) + '\t较昨日' + str(self.asymptomaticRelative)
|
||||
string+='\n\t重症:' + str(self.icu) + '\t较昨日' + str(self.icuRelative)
|
||||
string+='\n\t疑似:' + str(self.unconfirmed) + '\t\t较昨日' + str(self.unconfirmedRelative)
|
||||
string+='\n累计:\n\t确诊' + str(self.confirmed) + '\n\t治愈' + str(self.cured)
|
||||
string+='\n\t死亡' + str(self.died)
|
||||
return string
|
||||
|
||||
def getCnSummary():
|
||||
res = requests.get("https://voice.baidu.com/act/newpneumonia/newpneumonia/")
|
||||
txt = res.content.decode("utf-8")
|
||||
soup = BeautifulSoup(txt,'html.parser')
|
||||
tag = soup.find('script',attrs={'id':'captain-config'})
|
||||
tagjs = json.loads(tag.string)
|
||||
ans = tagjs['component'][0]['summaryDataIn']
|
||||
sum = summary_cn()
|
||||
|
||||
sum.confirmed = int(ans['confirmed'])
|
||||
sum.died = int(ans['died'])
|
||||
sum.cured = int(ans['cured'])
|
||||
sum.asymptomatic = int(ans['asymptomatic'])
|
||||
sum.asymptomaticRelative = int(ans['asymptomaticRelative'])
|
||||
sum.unconfirmed = int(ans['unconfirmed'])
|
||||
sum.relativeTime = int(ans['relativeTime'])
|
||||
sum.confirmedRelative = int(ans['confirmedRelative'])
|
||||
sum.unconfirmedRelative = int(ans['unconfirmedRelative'])
|
||||
sum.curedRelative = int(ans['curedRelative'])
|
||||
sum.diedRelative = int(ans['diedRelative'])
|
||||
sum.icu = int(ans['icu'])
|
||||
sum.icuRelative = int(ans['icuRelative'])
|
||||
sum.overseasInput = int(ans['overseasInput'])
|
||||
sum.unOverseasInputCumulative = int(ans['unOverseasInputCumulative'])
|
||||
sum.overseasInputRelative = int(ans['overseasInputRelative'])
|
||||
sum.unOverseasInputNewAdd = int(ans['unOverseasInputNewAdd'])
|
||||
sum.curConfirm = int(ans['curConfirm'])
|
||||
sum.curConfirmRelative = int(ans['curConfirmRelative'])
|
||||
sum.icuDisable = int(ans['icuDisable'])
|
||||
sum.mapLastUpdatedTime=tagjs['component'][0]['mapLastUpdatedTime']
|
||||
print(sum)
|
||||
return sum
|
||||
|
||||
def getCnNews():
|
||||
from selenium import webdriver
|
||||
b=webdriver.Chrome()
|
||||
b.get("https://voice.baidu.com/act/newpneumonia/newpneumonia")
|
||||
txt=b.page_source
|
||||
b.quit()
|
||||
soup = BeautifulSoup(txt,'html.parser')
|
||||
tag1 = soup.select('div[class="Virus_1-1-284_2CVyXP"]')
|
||||
tag2=soup.select('div[class="Virus_1-1-284_TB6x3k"] > a[href]')
|
||||
ans=[]
|
||||
for i,j in zip(tag1,tag2):
|
||||
tmp=str(i.string)
|
||||
tmp+=' '+j.get('href')
|
||||
ans.append(tmp)
|
||||
print(tmp)
|
||||
return ans
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
#undefined_D()
|
||||
#getCnNews()
|
Loading…
Reference in new issue