代码拉取完成,页面将自动刷新
# -*- coding: utf-8 -*-
# @Time : 2021/10/11 22:36
# @Author : JustFly
# @File : ts.py
# @Software : PyCharm
import requests
import json
import time
import pymysql
import traceback
from selenium import webdriver
def get_connphp():
"""
:return: 连接, 游标
"""
# 创建连接
conn = pymysql.connect(host="127.0.0.1",
user="root",
password="123456",
db="covid_2019",
)
# 创建游标
cursor = conn.cursor()
return conn, cursor
def get_conncts():
"""
:return: 连接, 游标
"""
# 创建连接
conn = pymysql.connect(host="1.15.49.8",
user="root",
password="jjf521zl!",
db="covid_2019",
)
# 创建游标
cursor = conn.cursor()
return conn, cursor
def close_conn(conn, cursor):
if cursor:
cursor.close()
if conn:
conn.close()
def querya(sql, *args):
"""
封装通用查询
:param sql:
:param args:
:return:元组
"""
conn, cursor = get_connphp()
cursor.execute(sql, args)
res = cursor.fetchall()
# print(res)
close_conn(conn, cursor)
return res
def queryb(sql, *args):
"""
封装通用查询
:param sql:
:param args:
:return:元组
"""
conn, cursor = get_conncts()
cursor.execute(sql, args)
res = cursor.fetchall()
# print(res)
close_conn(conn, cursor)
return res
conna, cursora = get_connphp()
connb, cursorb = get_conncts()
sqla = "select * from history"
data_a = querya(sqla)
for d in data_a:
sqlb = "insert into history(ds, confirm, confirm_add, suspect, suspect_add, heal, heal_add, dead, dead_add)" \
" values (%s, %s, %s, %s, %s, %s, %s, %s, %s)"
print(d[0])
cursorb.execute(sqlb, d)
connb.commit()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。