zoukankan      html  css  js  c++  java
  • 疫情数据爬取实战

    原网址:https://news.qq.com/zt2020/page/feiyan.htm?from=timeline&isappinstalled=0

    import time
    import json
    import csv
    import requests
    ExcelName = 'C:/Epidemic-data.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(["省份","城市","确诊","死亡","治愈","时间"])
        
    for contry in datas['areaTree']:
        if contry['name'] == '中国':
            for province in contry['children']:
                for city in province['children']:
                    with open(ExcelName, 'a', encoding='utf-8', newline='') as csvfile:
                        writer = csv.writer(csvfile)
                        writer.writerow([province['name'],city['name'], str(city['total']['confirm']),str(city['total']['dead']), str(city['total']['
    heal']),datas['lastUpdateTime']])

    爬取结果:

  • 相关阅读:
    光与爱的世界
    [家里训练20_02_28]ABC
    [爬虫]美术作业,爬虫和百度图片
    [机器学习]第六、七周记录
    数据类型和对象
    设备对象
    进程、内存线程
    创建符号链接
    SCM管理器
    Nt内核函数原型and中文
  • 原文地址:https://www.cnblogs.com/123456www/p/12314047.html
Copyright © 2011-2022 走看看