#
# made by 杨庆华
import urllib.request,urllib.parse
import time
import json,csv
def handleRequest(url):
headers = { 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36'}
request = urllib.request.Request(url=url,headers=headers);
return request;
def handleData(response):
result = response.read().decode();
result = json.loads(result)
jsonList = result["data"];
# 定义列表 : 国家名字 洲 日期 累计确诊人数 死亡人数 治愈人数
Cname_List = list()
continent_List = list()
date_List = list()
month_List = list()
day_List = list()
confirmAdd_List = list()
dead_List = list()
heal_List = list()
cnt = 0
for item_Data in jsonList:
Cname_List.append(jsonList[cnt]['name'])
continent_List.append((jsonList[cnt]['continent']))
month, day = jsonList[cnt]['date'].split('.')
month_List.append(month)
day_List.append(day)
confirmAdd_List.append(jsonList[cnt]['confirmAdd'])
dead_List.append(jsonList[cnt]['dead'])
heal_List.append(jsonList[cnt]['heal'])
cnt += 1
return Cname_List, continent_List, month_List, day_List, confirmAdd_List, dead_List, heal_List
def main():
url = "https://api.inews.qq.com/newsqa/v1/automation/foreign/country/ranklist";
request = handleRequest(url);
response = urllib.request.urlopen(request);
# print(response.read().decode())
handleData(response)
if __name__ == "__main__":
main();
12-29
747
01-07
12-22