|
|
|
@ -14,6 +14,10 @@ class Spider():
|
|
|
|
|
self.news=[]
|
|
|
|
|
#网站消息更新时间
|
|
|
|
|
self.modifytime=''
|
|
|
|
|
#国外疫情信息
|
|
|
|
|
self.foreignCountry=[]
|
|
|
|
|
#国内疫情信息
|
|
|
|
|
self.provinces=[]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 获取实时新闻
|
|
|
|
@ -66,7 +70,7 @@ class Spider():
|
|
|
|
|
timestr = time.strftime("%Y-%m-%d %H:%M:%S", localt)
|
|
|
|
|
|
|
|
|
|
self.modifytime=timestr
|
|
|
|
|
print(timestr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 获取国内疫情
|
|
|
|
|
def grapchina(self):
|
|
|
|
@ -111,6 +115,8 @@ class Spider():
|
|
|
|
|
cityinfo.deadCount=cj['deadCount']
|
|
|
|
|
province.cities.append(cityinfo)
|
|
|
|
|
provinces.append(province)
|
|
|
|
|
|
|
|
|
|
self.provinces=provinces
|
|
|
|
|
return provinces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -124,7 +130,27 @@ class Spider():
|
|
|
|
|
#查找数据
|
|
|
|
|
tag=soup.find('script',attrs={'id':'getListByCountryTypeService2true'})
|
|
|
|
|
yiqinginfo=str(tag)
|
|
|
|
|
|
|
|
|
|
# 使用正则表达式匹配
|
|
|
|
|
results = re.findall(r'(\{"id".*?"showRank".*?\})', yiqinginfo)
|
|
|
|
|
all_countries = []
|
|
|
|
|
for item in results:
|
|
|
|
|
country = ForeignCountry()
|
|
|
|
|
itemJson = json.loads(item)
|
|
|
|
|
country.provinceName = itemJson['provinceName']
|
|
|
|
|
country.provinceShortName = itemJson['provinceShortName']
|
|
|
|
|
country.currentConfirmedCount=int(itemJson['currentConfirmedCount'])
|
|
|
|
|
country.confirmedCount = int(itemJson['confirmedCount'])
|
|
|
|
|
country.suspectedCount = int(itemJson['suspectedCount'])
|
|
|
|
|
country.curedCount = int(itemJson['curedCount'])
|
|
|
|
|
country.deadCount = int(itemJson['deadCount'])
|
|
|
|
|
country.deadRate = float(itemJson['deadRate'])
|
|
|
|
|
country.countryShortCode = itemJson['countryShortCode']
|
|
|
|
|
country.countryFullName = itemJson['countryFullName']
|
|
|
|
|
country.continents = itemJson['continents']
|
|
|
|
|
all_countries.append(country)
|
|
|
|
|
|
|
|
|
|
self.foreignCountry=all_countries
|
|
|
|
|
return all_countries
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#news类用来存储实时新闻的信息
|
|
|
|
@ -184,3 +210,22 @@ class Provinceinfo():
|
|
|
|
|
self.deadCount = 0
|
|
|
|
|
# 各个市的疫情信息,通过一个字典存储
|
|
|
|
|
self.cities = []
|
|
|
|
|
|
|
|
|
|
#国外疫情信息存储类
|
|
|
|
|
class ForeignCountry:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.provinceName = ''
|
|
|
|
|
self.provinceShortName = ''
|
|
|
|
|
self.currentConfirmedCount = 0
|
|
|
|
|
self.confirmedCount = 0
|
|
|
|
|
self.suspectedCount = 0
|
|
|
|
|
self.curedCount = 0
|
|
|
|
|
self.deadCount = 0
|
|
|
|
|
self.deadRate = 0
|
|
|
|
|
self.countryShortCode = ''
|
|
|
|
|
self.countryFullName = ''
|
|
|
|
|
self.continents = ''
|
|
|
|
|
def __str__(self):
|
|
|
|
|
return '%s,当前确诊:%d,累计确诊:%d,疑似:%d, 治愈: %d, 死亡: %d, 死亡率: %s,洲: %s'\
|
|
|
|
|
%(self.provinceName,self.currentConfirmedCount,self.confirmedCount,
|
|
|
|
|
self.suspectedCount, self.curedCount, self.deadCount, self.deadRate,self.continents)
|