zoukankan      html  css  js  c++  java
  • python爬取世界疫情数据

    import time, json, requests
    import csv
    
    #文件名称
    ExcelName = 'E:/hhh.csv'
    
    #当前日期时间戳
    number = format(time.time() * 100, '.0f')
    
    url = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&callback=&_=%s' % number
    datas = json.loads(requests.get(url=url).json()['data'])
    
    print('更新时间:' + datas['lastUpdateTime'])
    
    #写入表头
    with open(ExcelName, 'w', encoding='utf-8', newline='') as csvfile:
        writer = csv.writer(csvfile)
        writer.writerow(["country","confirm","die","cure","time"])
    
    
    
    for contry in datas['areaTree']:
        #if contry['name'] == '中国':
            #for province in contry['children']:
                #print(province['name'])
                #with open(ExcelName, 'a', encoding='utf-8', newline='') as csvfile:
                    #writer = csv.writer(csvfile)
                    #writer.writerow([province['name']])
                #for city in province['children']:
                    print(contry['name'], '确诊:' + str(contry['total']['confirm']), '死亡:' + str(contry['total']['dead']), '治愈:' + str(contry['total']['heal']))
                    # 写入市的名称,确诊、死亡、治愈的人数
                    with open(ExcelName, 'a', encoding='utf-8', newline='') as csvfile:
                        writer = csv.writer(csvfile)
                        writer.writerow([contry['name'], str(contry['total']['confirm']),str(contry['total']['dead']), str(contry['total']['heal']),datas['lastUpdateTime']])
  • 相关阅读:
    数据库分表分库
    rabbitMq 集群
    马哥博客作业第七周
    马哥博客作业第六周
    马哥博客作业第一阶段考试
    马哥博客作业第四周
    马哥博客作业第三周
    马哥博客作业第二周
    马哥博客作业第一周
    03-MySQL数据库表的基本操作
  • 原文地址:https://www.cnblogs.com/xrj-/p/12550925.html
Copyright © 2011-2022 走看看