diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..40acaa4 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/../../../../../:\PyCharm\文件\疫情数据分析\.idea/dataSources/ +/dataSources.local.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8161a60 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..8f5f2b2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/疫情数据分析.iml b/.idea/疫情数据分析.iml new file mode 100644 index 0000000..b7077a5 --- /dev/null +++ b/.idea/疫情数据分析.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/__pycache__/国外总数据.cpython-37.pyc b/__pycache__/国外总数据.cpython-37.pyc new file mode 100644 index 0000000..272c63b Binary files /dev/null and b/__pycache__/国外总数据.cpython-37.pyc differ diff --git a/国外总数据.py b/国外总数据.py new file mode 100644 index 0000000..9eca84b --- /dev/null +++ b/国外总数据.py @@ -0,0 +1,25 @@ +class summaryDataOut: + confirmed=0 + died=0 + curConfirm=0 + cured=0 + confirmedRelative=0 + curedRelative=0 + diedRelative=0 + curConfirmRelative=0 + relativeTime=0 + time='' + + def blankNum (self,object): + return ' '*(12-len(str(object))) + + def PrintOut(self): + print("截至%s国外疫情概况:"%self.time) + print("现有确诊:%d" % self.curConfirm, end=self.blankNum(self.curConfirm)) + print("相对昨日新增:%d"%self.curConfirmRelative) + print("累计确诊:%d"%self.confirmed,end=self.blankNum(self.confirmed)) + print("相对昨日新增:%d"%self.confirmedRelative) + print("累计治愈:%d"%self.cured,end=self.blankNum(self.cured)) + print("相对昨日新增:%d"%self.curedRelative) + print("累计死亡:%d"%self.died,end=self.blankNum(self.died)) + print("相对昨日新增:%d"%self.diedRelative) diff --git a/爬取网站.py b/爬取网站.py new file mode 100644 index 0000000..2955d49 --- /dev/null +++ b/爬取网站.py @@ -0,0 +1,34 @@ +import requests +import re +from bs4 import BeautifulSoup +import json + +from 国外总数据 import summaryDataOut + +# 获取数据 +req = requests.get ('https://voice.baidu.com/act/newpneumonia/newpneumonia/?from=osari_pc_3#tab4') +content = req.content.decode('utf-8') +soup = BeautifulSoup(content,'html.parser') + +# 过滤筛选 +tag = soup.find('script',attrs={'type':'application/json','id':'captain-config'}) +tagstr=tag.string #标签转化为字符串 +tagdic=json.loads(tagstr) #标签字符串转化为字典 +component=tagdic['component'][0] +time= component['mapLastUpdatedTime'] +result = component['summaryDataOut'] #字典中找出'component'key下的'summaryDataOut'key内容 + +# 存储 +OutData=summaryDataOut() + +OutData.confirmed=int(result['confirmed']) +OutData.confirmedRelative=int(result['confirmedRelative']) +OutData.cured=int(result['cured']) +OutData.curedRelative=int(result['curedRelative']) +OutData.died=int(result['died']) +OutData.diedRelative=int(result['diedRelative']) +OutData.curConfirm=int(result['curConfirm']) +OutData.curConfirmRelative=int(result['curConfirmRelative']) +OutData.time=time + +OutData.PrintOut() \ No newline at end of file diff --git a/需求文档.docx b/需求文档.docx new file mode 100644 index 0000000..b8ed49c Binary files /dev/null and b/需求文档.docx differ