各国疫情人数Python爬虫

最近国内疫情渐趋平稳,胜利在望,国外忧患又起。国外一所大学做了一个各国疫情人数在线追踪,发现其中有个网页返回的json数据中含各国疫情数据,写了一个小爬虫爬取这个结果并简单输出,代码如下:

# 引入库
import requests
import json
# 拉回网页
r = requests.get("https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=Confirmed%20%3E%200&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Confirmed%20desc%2CCountry_Region%20asc%2CProvince_State%20asc&outSR=102100&resultOffset=0&resultRecordCount=250&cacheHint=true")
# 解析json格式的数据
vData = json.loads(r.text)
for i in vData["features"]:
    vCountry = "国家:" + str(i["attributes"]["Country_Region"]) + ";"
    vProvince = "地区:" + str(i["attributes"]["Province_State"]).replace("None", "") + ";"
    vConfirmed = "确诊人数:" + str(i["attributes"]["Confirmed"]) + ";"
    vDeaths = "死亡人数:" + str(i["attributes"]["Deaths"]) + ";"
    vRecovered = "治愈人数:" + str(i["attributes"]["Recovered"])
    # 输出数据
    print(vCountry + vProvince + vConfirmed + vDeaths + vRecovered)
# 保持命令行不退出
vText = input("敲击任意键后退出")

你可能感兴趣的:(各国疫情人数Python爬虫)