dlmltao

连接数据库需要先pip install PyMySQL

import pymysql
import re

def spotSql(dbhost,dbport,dbuser,dbpasswd,dbdatabase,dbsql):
    # 打开数据库连接
    db = pymysql.connect(host=dbhost,
                         port=dbport,
                         user=dbuser,
                         passwd=dbpasswd,
                         database=dbdatabase)
    # 使用cursor()方法获取操作游标
    cur = db.cursor()
    # 使用execute方法执行SQL语句
    cur.execute(dbsql)
    # 使用 fetchone() 方法获取一条数据
    data = cur.fetchall()
    # 关闭数据库连接
    db.close()
    return data

if __name__ == \'__main__\':
    db_host = \'localhost\'
    db_port = \'port\'
    db_user = \'test\'
    db_passwd = \'123456\'
    db_database = \'msgemail\'
    mysqltest = "select * from table"

    response = spotSql(db_host, db_port, db_user, db_passwd, db_database, mysqltest)
    #显示查询结果
    b = response[0][0]
    # print("**************response**************:",response)
    code = re.findall(r"验证码:(.+?),验证码", b)
    print("**************code**************:",code)

分类:

技术点:

相关文章:

  • 2022-01-21
  • 2022-03-07
  • 2021-08-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-20
  • 2021-12-20
  • 2021-11-21
  • 2021-12-20
  • 2021-11-21
  • 2021-12-02
相关资源
相似解决方案