• 2021年3月25日


    时间:2个小时左右

    代码:100行左右

    博客:1

    内容:使用了flask框架进行了疫情数据的爬取

    import requests
    import json
    
    # https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5
    # https://view.inews.qq.com/g2/getOnsInfo?name=disease_foreign
    
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
    
    }
    # 历史数据
    url_history = "https://view.inews.qq.com/g2/getOnsInfo?name=disease_foreign"
    resp = requests.get(url_history, headers)
    # 获取页面的json字符串
    json_data = resp.text
    print(type(json_data))
    print(json_data)
    # 把json转换为dict
    d_data = json.loads(json_data)
    print(type(d_data))
    print(d_data)
    
    print(d_data['data'])
    data_history = json.loads(d_data['data'])
    for item in data_history.keys():
        print(item)
        print(data_history[item])
    
    # details 详细数据
    url = "https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"
    
    resp = requests.get(url, headers)
    
    json_data = resp.text
    print(json_data)
    # 转换为字典
    dict_data = json.loads(json_data)
    print(dict_data)
    
    data = json.loads(dict_data['data'])
    for item in data.keys():
        print(item)
        print(data[item])
    
    print(data['chinaTotal'])
    print(data['chinaAdd'])
    
    print(data['areaTree'])
    
    print("*******")
    
    i = 1
    for item in data['areaTree'][0]:
        print(item)
    
    for item in data['areaTree'][0]['children']:
        print(item)

  • 相关阅读:
    基于最大最小距离的分类数目上限K确定的聚类方法
    diff函数(matlab)
    CreateThread线程函数
    套接字基础
    基于TCP套接字实现的简单Demo
    使用httpwatch抓包
    TLV----Demo讲解
    关于位图边缘的检测定位
    从txt中读入数据到数组中(fscanf)
    C语言运算符的优先级
  • 原文地址:https://www.cnblogs.com/j-y-s/p/14903195.html
Copyright © 2020-2023  润新知