新冠疫情数据爬取
Project description
功能介绍
支持全球疫情数据获取以及对应的国家、省份、城市数据获取
具体操作
import violetSpider as spider
from violetSpider.core.model import Word, Nation, Province
# 1.获取全球数据
word: Word = spider.find_word()
print(word, type(word))
# <violetSpider.core.model.World object at 0x0000021DD6FC3AC8> <class 'violetSpider.core.model.World'>
# 2.获取对应数据
# 获取该对象上所有的存储数据的 Key,drop=True【默认删除值为 None 的 Key】
keys = word.keys(drop=True)
values = word.values(drop=True)
value = word.name
print(keys, values, value)
# dict_keys(['name', 'nowConfirm', 'confirm', 'heal', 'dead', 'lastUpdateTime'])
# dict_values(['地球', 46987153, 217021468, 165524088, 4510227, '2021-10-20 13:43:34'])
# 地球
获取国家数据
# 根据全球数据获取国家数据
# 如果不指定具体国家,会获取所有国家
# 所有数据对象都包含 keys() 和 values()
nations: list = word.searchNation('美国', '法国', '西班牙')
nation: Nation = nations[0]
print(nations)
print(nation.keys(), nation.values())
# [<violetSpider.core.model.Nation object at 0x000002245C37AD30>,
# <violetSpider.core.model.Nation object at 0x000002245C37ACF8>,
# <violetSpider.core.model.Nation object at 0x000002245C37AC88>]
# dict_keys(['name', 'continent', 'y', 'date', 'confirmAdd', 'confirmAddCut', 'confirm', 'suspect', 'dead', 'heal', 'nowConfirm', 'confirmCompare', 'nowConfirmCompare', 'healCompare', 'deadCompare'])
# dict_values(['美国', '北美洲', '2021', '08.31', 0, 0, 39668541, 0, 654696, 30826478, 8187367, 0, 0, 0, 0])
获取某个国家下的省份数据
# 先获取具体国家
nation: Nation = word.searchNation_one('美国')
# 获取指定省份,如果不指定则获取所有
provinces = nation.searchProvince()
for province in provinces[:3]:
print(province.name)
# 加利福尼亚
# 德克萨斯
# 佛罗里达
获取省份下面的城市
nation: Nation = word.searchNation_one('美国')
province: Province = nation.searchProvince_one('德克萨斯')
# 获取指定城市,如果不指定则获取所有
citys = province.searchCity()
for city in citys[:3]:
print(city)
# 当然,有些省份是没有公布城市数据的
# violetSpider.core.error.WorldData: 很抱歉, 德克萨斯, 并未开放城市数据
# 所有你可以这样写
# 不过别报太大希望,城市一般不会获取到数据
nation: Nation = word.searchNation_one('美国')
provinces = nation.searchProvince()
for province in provinces:
try:
c = province.searchCity()[:3]
for city in c:
print(city.name)
print(province.name)
break
except Exception as e:
print(e)
保存数据
# 目前支持 mysql 和 csv 保持
# 具体 API 如下
import violetSpider as spider
spider.save_csv(
path: str, # 存储路径,必须
data: list, # 数据,装有 Nation、Province、City 对象的列表
fields=None, # 存储指定,不指定则全选
drop=True # 是否删除空值字段
)
spider.save_mysql(
username: str,
password: str,
host: str,
port: int,
databases: str,
data: list, # 数据,装有 Nation、Province、City 对象的列表
table=None, # 是否指定表
fields=None, # 指定保存的字段
drop=True # 只要有一个字段的值为空, 那么便不保存这个字段
)
更新内容
1.1.0 -> 基本功能实现
1.1.3 -> 修复了 china 数据无法获取
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file violetSpider-1.1.3-py3-none-any.whl.
File metadata
- Download URL: violetSpider-1.1.3-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e4f88e3c6c605110ae10b66228835e44e5e830c7fc687beabfa35899cf4306e
|
|
| MD5 |
73715f793de8ddf27afaa2d000516aae
|
|
| BLAKE2b-256 |
2da54dbb6bb27fe625ae13e6a4f101b575a32660851d8cacf65559c8047deac8
|