zoukankan      html  css  js  c++  java
  • 团队项目冲刺第四天

    今天做了一些其他的事,爬取了世界疫情情况。之后就可以用echarts图表显示出世界地图疫情显示。

    import json
    import pymysql
    import requests
    from bs4 import BeautifulSoup
    import datetime
    url = 'https://ncov.dxy.cn/ncovh5/view/pneumonia?from=timeline&isappinstalled=0' # 请求地址
    headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36'} # 创建头部信息
    response = requests.get(url, headers=headers) # 发送网络请求
    content = response.content.decode('utf-8')
    soup = BeautifulSoup(content, 'html.parser')
    # 世界确诊getAreaStat
    listB = soup.find_all(name='script', attrs={"id": "getListByCountryTypeService2true"})
    world_messages = str(listB)[95:-21]
    print(world_messages)
    world_messages_json = json.loads(world_messages)
    worldList = []
    now_time = datetime.datetime.now().strftime('%Y-%m-%d')
    for k in range(len(world_messages_json)):
    worldvalue = (now_time,
    world_messages_json[k].get('countryType'), world_messages_json[k].get('continents'),
    world_messages_json[k].get('provinceId'), world_messages_json[k].get('provinceName'),
    world_messages_json[k].get('provinceShortName'), world_messages_json[k].get('cityName'),
    world_messages_json[k].get('currentConfirmedCount'), world_messages_json[k].get('confirmedCount'),
    world_messages_json[k].get('suspectedCount'), world_messages_json[k].get('curedCount'),
    world_messages_json[k].get('deadCount'), world_messages_json[k].get('locationId'),
    world_messages_json[k].get('countryShortCode'),)
    worldList.append(worldvalue)
    db = pymysql.connect("localhost", "root", "163216", "yiqing", charset='utf8')
    cursor = db.cursor()
    sql_world = "INSERT INTO world_map values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
    worldTuple = tuple(worldList)
    print(worldTuple)
    try:
    cursor.executemany(sql_world, worldTuple)
    db.commit()
    except:
    print('执行失败,进入回调2')
    db.rollback()

    db.close()
  • 相关阅读:
    php composer 相关及版本约束等小技巧
    Jquery 获取表单值如input,select等方法
    Apache benchmark 压力测试工具
    Linux中的随机数文件 /dev/random /dev/urandom
    redis持久化
    Python---装饰器
    高仿拉手网底部菜单实现FragmentActivity+Fragment+RadioGroup
    python实现二叉树和它的七种遍历
    Spring AOP应用实例demo
    二维数组的列排序
  • 原文地址:https://www.cnblogs.com/aiyyue/p/12734701.html
Copyright © 2011-2022 走看看