Python 操作 pymysql 批量 增、删、改、查

github:https://github.com/PyMySQL/PyMySQL

Python3 MySQL 数据库连接 - PyMySQL 驱动:https://www.runoob.com/python3/python3-mysql.html

pymysql 是线程安全的( 搜索 thread,可以看到 thread_safe=1,同时函数 thread_safe() 返回 True ):https://github.com/PyMySQL/PyMySQL/blob/main/pymysql/__init__.py

Mysql  如果数据存在则更新,不存在则插入

:https://blog.csdn.net/zhou16333/article/details/95867827

1、PyMySQL 安装

在使用 PyMySQL 之前,我们需要确保 PyMySQL 已安装。

PyMySQL 下载地址:https://github.com/PyMySQL/PyMySQL

安装 PyMySQL 的 Python 包:pip3 install PyMySQL

2、数据库连接

连接数据库前,请先确认以下事项:

  • 已经创建了数据库 TESTDB.
  • TESTDB 数据库中您已经创建了表 EMPLOYEE
  • EMPLOYEE 表字段为 FIRST_NAME, LAST_NAME, AGE, SEXINCOME
  • 连接数据库 TESTDB 使用的用户名为 "testuser" ,密码为 "test123",你可以可以自己设定或者直接使用 root 用户名及其密码,Mysql 数据库用户授权请使用 Grant 命令。
  • 已经安装了 Python MySQLdb 模块。
  • 如果您对sql语句不熟悉,可以访问 SQL基础教程

示  例:

链接 Mysql 的 TESTDB 数据库:

import pymysql# 打开数据库连接
db = pymysql.connect("localhost","testuser","test123","TESTDB" )# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()# 使用 execute()  方法执行 SQL 查询 
cursor.execute("SELECT VERSION()")# 使用 fetchone() 方法获取单条数据.
data = cursor.fetchone()print ("Database version : %s " % data)# 关闭数据库连接
db.close()

3、使用

创建数据库表

如果数据库连接存在我们可以使用execute()方法来为数据库创建表,如下所示创建表EMPLOYEE:

import pymysql# 打开数据库连接
db = pymysql.connect("localhost","testuser","test123","TESTDB" )# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()# 使用 execute() 方法执行 SQL,如果表存在则删除
cursor.execute("DROP TABLE IF EXISTS EMPLOYEE")# 使用预处理语句创建表
sql = """CREATE TABLE EMPLOYEE (FIRST_NAME  CHAR(20) NOT NULL,LAST_NAME  CHAR(20),AGE INT,  SEX CHAR(1),INCOME FLOAT )"""cursor.execute(sql)# 关闭数据库连接
db.close()

查询  数据

Python 查询 Mysql 使用 fetchone() 方法获取单条数据,使用 fetchall() 方法获取多条数据。

  • fetchone():  该方法获取下一个查询结果集。结果集是一个对象
  • fetchall():  接收全部的返回结果行.
  • rowcount:  这是一个只读属性,并返回执行execute()方法后影响的行数。

查询 EMPLOYEE 表中 salary(工资)字段大于 1000 的所有数据:

import pymysql# 打开数据库连接
db = pymysql.connect("localhost","testuser","test123","TESTDB" )# 使用cursor()方法获取操作游标 
cursor = db.cursor()# SQL 查询语句
sql = "SELECT * FROM EMPLOYEE \WHERE INCOME > %s" % (1000)
try:# 执行SQL语句cursor.execute(sql)# 获取所有记录列表results = cursor.fetchall()for row in results:fname = row[0]lname = row[1]age = row[2]sex = row[3]income = row[4]# 打印结果print ("fname=%s,lname=%s,age=%s,sex=%s,income=%s" % \(fname, lname, age, sex, income ))
except:print ("Error: unable to fetch data")# 关闭数据库连接
db.close()

示例:

import pymysqlclass DB():def __init__(self, host='localhost', port=3306, db='', user='root', passwd='root', charset='utf8'):# 建立连接 self.conn = pymysql.connect(host=host, port=port, db=db, user=user, passwd=passwd, charset=charset)# 创建游标,操作设置为字典类型        self.cur = self.conn.cursor(cursor = pymysql.cursors.DictCursor)def __enter__(self):# 返回游标        return self.curdef __exit__(self, exc_type, exc_val, exc_tb):# 提交数据库并执行        self.conn.commit()# 关闭游标        self.cur.close()# 关闭数据库连接        self.conn.close()if __name__ == '__main__':with DB(host='192.168.68.129',user='root',passwd='zhumoran',db='text3') as db:db.execute('select * from course')print(db)for i in db:print(i)

插入  数据

执行 SQL INSERT 语句向表 EMPLOYEE 插入记录:

import pymysql# 打开数据库连接
db = pymysql.connect("localhost","testuser","test123","TESTDB" )# 使用cursor()方法获取操作游标 
cursor = db.cursor()# SQL 插入语句
sql = """INSERT INTO EMPLOYEE(FIRST_NAME,LAST_NAME, AGE, SEX, INCOME)VALUES ('Mac', 'Mohan', 20, 'M', 2000)"""
try:# 执行sql语句cursor.execute(sql)# 提交到数据库执行db.commit()
except:# 如果发生错误则回滚db.rollback()# 关闭数据库连接
db.close()

以上例子也可以写成如下形式:

import pymysql# 打开数据库连接
db = pymysql.connect("localhost","testuser","test123","TESTDB" )# 使用cursor()方法获取操作游标 
cursor = db.cursor()# SQL 插入语句
sql = "INSERT INTO EMPLOYEE(FIRST_NAME, \LAST_NAME, AGE, SEX, INCOME) \VALUES ('%s', '%s',  %s,  '%s',  %s)" % \('Mac', 'Mohan', 20, 'M', 2000)
try:# 执行sql语句cursor.execute(sql)# 执行sql语句db.commit()
except:# 发生错误时回滚db.rollback()# 关闭数据库连接
db.close()

以下代码使用变量向SQL语句中传递参数:

..................................
user_id = "test123"
password = "password"con.execute('insert into Login values( %s,  %s)' % \(user_id, password))
..................................

单条插入数据:

 
#!/usr/bin/python3import pymysql# 打开数据库连接
db = pymysql.connect("localhost","testuser","test123","TESTDB" )# 使用cursor()方法获取操作游标 
cursor = db.cursor()# SQL 插入语句  里面的数据类型要对应
sql = "INSERT INTO EMPLOYEE(FIRST_NAME, \LAST_NAME, AGE, SEX, INCOME) \VALUES ('%s', '%s',  %s,  '%s',  %s)" % \('Mac', 'Mohan', 20, 'M', 2000)
try:# 执行sql语句cursor.execute(sql)# 执行sql语句db.commit()
except:# 发生错误时回滚db.rollback()# 关闭数据库连接
db.close()

批量插入数据:

注意:批量插入数据单条插入数据 的区别:

  • 批量插入:VALUES (%s, %s, %s, %s, %s,) 里面 不用引号
  • 单条插入:VALUES ('%s', '%s', '%s', '%s', '%s') 里面 需要引号
#!/usr/bin/env python
# -*-encoding:utf-8-*-import pymysql# 打开数据库连接
db = pymysql.connect("localhost","root","123","testdb")# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()# SQL 插入语句
sql = "INSERT INTO EMPLOYEE(FIRST_NAME, \LAST_NAME, AGE, SEX, INCOME) \VALUES (%s,%s,%s,%s,%s)"
# 区别与单条插入数据,VALUES ('%s', '%s',  %s,  '%s', %s) 里面不用引号val = (('li', 'si', 16, 'F', 1000),('Bruse', 'Jerry', 30, 'F', 3000),('Lee', 'Tomcat', 40, 'M', 4000),('zhang', 'san', 18, 'M', 1500))
try:# 执行sql语句cursor.executemany(sql,val)# 提交到数据库执行db.commit()
except:# 如果发生错误则回滚db.rollback()# 关闭数据库连接
db.close()

更新  数据

更新操作用于更新数据表的数据,以下实例将 TESTDB 表中 SEX 为 'M' 的 AGE 字段递增 1:

import pymysql# 打开数据库连接
db = pymysql.connect("localhost","testuser","test123","TESTDB" )# 使用cursor()方法获取操作游标 
cursor = db.cursor()# SQL 更新语句
sql = "UPDATE EMPLOYEE SET AGE = AGE + 1 WHERE SEX = '%c'" % ('M')
try:# 执行SQL语句cursor.execute(sql)# 提交到数据库执行db.commit()
except:# 发生错误时回滚db.rollback()# 关闭数据库连接
db.close()

批量 更新

使用 pymysql 的 course.executemany(sql, update_list) 进行批量更新

  • sql:更新一条的 sql 语句模板;
  • update_list:一个列表套元组的结构;

示  例:

db = pymysql.connect(user='root', password='mysql', database='test', host='127.0.0.1', port=3306, charset='utf8mb4')name_list = ["re", "gh", "ds", "D"]  # 存储name的值
age_list = ["10", "20", "30", "40"]  # 存储age的值
id_list = ["1", "2", "3", "4"]  # 存储id的值
val_list = [[name_list[i], age_list[i], id_list[i]] for i in range(len(id_list))]
print(val_list)
# [['re', '10', '1'], ['gh', '20', '2'], ['ds', '30', '3'], ['D', '40', '4']]with db.cursor() as cursor:try:sql = "UPDATE test SET name=(%s), age=(%s) WHERE id=(%s)"cursor.executemany(sql, val_list)db.commit()except:db.rollback()
db.close()

pymysql 批量 --- 增、删、改、查

注意:插入数字也是 %s

# coding=utf-8import time
import pymysql.cursorsconn= pymysql.connect(host='rm-xxx.mysql.rds.aliyuncs.com',port=3306,user='dba',password='xxxxx',db='app',charset='utf8')
cursor= conn.cursor()
# conn.ping(reconnect=True)count= 0
posts=[]
for postin posts:try:sql= 'DELETE FROM user_like WHERE user_id=%s and like_post_id=%s'ret= cursor.executemany(sql, ((1,2), (3,4), (5,6)))conn.commit()except Exception as e:print("batch Exception:", e)count+=1cursor.close()
conn.close()# 基本sql语句写法
# INSERT INTO star(name,gender) VALUES(“XX”, 20)
# SELECT * FROM app.user_post WHERE post_id LIKE '%xxxx%';
# UPDATE app.user_post SET post_id=replace(post_id,'\'','’);
# UPDATE app.user_post SET  province = ‘xxx', city =‘xxx';
# DELETE FROM app.user_post where updated_at = '0000-00-00 00:00:00’;# 带参数构造语句的基本写法
# sql = 'select user_id, post_id from user_post where user_id="{user_id}" and post_id="{post_id}"'.format(user_id=user_id, post_id=post_id)
# sql = 'SELECT count(*) FROM user_like where like_post_id = "%s"' % ("xxx")
# sql = 'update star set gender="{gender}", height="{height}" where star_id="{star_id}"'.format(gender='M', height=180, star_id=123456789)

删除  数据

删除操作用于删除数据表中的数据,以下实例演示了删除数据表 EMPLOYEE 中 AGE 大于 20 的所有数据:

import pymysql# 打开数据库连接
db = pymysql.connect("localhost","testuser","test123","TESTDB" )# 使用cursor()方法获取操作游标 
cursor = db.cursor()# SQL 删除语句
sql = "DELETE FROM EMPLOYEE WHERE AGE > %s" % (20)
try:# 执行SQL语句cursor.execute(sql)# 提交修改db.commit()
except:# 发生错误时回滚db.rollback()# 关闭连接
db.close()

执行 事务

事务机制可以确保数据一致性。

对于支持事务的数据库, 在 Python 数据库编程中,当游标建立之时,就自动开始了一个隐形的数据库事务。commit()方法游标的所有更新操作,rollback()方法回滚当前游标的所有操作。每一个方法都开始了一个新的事务。

事务应该具有4个属性:原子性、一致性、隔离性、持久性。这四个属性通常称为ACID特性。

  • 原子性(atomicity)。一个事务是一个不可分割的工作单位,事务中包括的诸操作要么都做,要么都不做。
  • 一致性(consistency)。事务必须是使数据库从一个一致性状态变到另一个一致性状态。一致性与原子性是密切相关的。
  • 隔离性(isolation)。一个事务的执行不能被其他事务干扰。即一个事务内部的操作及使用的数据对并发的其他事务是隔离的,并发执行的各个事务之间不能互相干扰。
  • 持久性(durability)。持续性也称永久性(permanence),指一个事务一旦提交,它对数据库中数据的改变就应该是永久性的。接下来的其他操作或故障不应该对其有任何影响。

示例:

# SQL删除记录语句
sql = "DELETE FROM EMPLOYEE WHERE AGE > %s" % (20)
try:# 执行SQL语句cursor.execute(sql)# 向数据库提交db.commit()
except:# 发生错误时回滚db.rollback()

pymysqlpool

线程安全 pymysqlpool

# -*-coding: utf-8-*-
# Author : Christopher Lee
# License: Apache License
# File   : test_example.py
# Date   : 2017-06-18 01-23
# Version: 0.0.1
# Description: simple test.import logging
import string
import threadingimport pandas as pd
import randomfrom pymysqlpool import ConnectionPoolconfig = {'pool_name': 'test','host': 'localhost','port': 3306,'user': 'root','password': 'chris','database': 'test','pool_resize_boundary': 50,'enable_auto_resize': True,# 'max_pool_size': 10
}logging.basicConfig(format='[%(asctime)s][%(name)s][%(module)s.%(lineno)d][%(levelname)s] %(message)s',datefmt='%Y-%m-%d %H:%M:%S',level=logging.DEBUG)def connection_pool():# Return a connection pool instancepool = ConnectionPool(**config)# pool.connect()return pooldef test_pool_cursor(cursor_obj=None):cursor_obj = cursor_obj or connection_pool().cursor()with cursor_obj as cursor:print('Truncate table user')cursor.execute('TRUNCATE user')print('Insert one record')result = cursor.execute('INSERT INTO user (name, age) VALUES (%s, %s)', ('Jerry', 20))print(result, cursor.lastrowid)print('Insert multiple records')users = [(name, age) for name in ['Jacky', 'Mary', 'Micheal'] for age in range(10, 15)]result = cursor.executemany('INSERT INTO user (name, age) VALUES (%s, %s)', users)print(result)print('View items in table user')cursor.execute('SELECT * FROM user')for user in cursor:print(user)print('Update the name of one user in the table')cursor.execute('UPDATE user SET name="Chris", age=29 WHERE id = 16')cursor.execute('SELECT * FROM user ORDER BY id DESC LIMIT 1')print(cursor.fetchone())print('Delete the last record')cursor.execute('DELETE FROM user WHERE id = 16')def test_pool_connection():with connection_pool().connection(autocommit=True) as conn:test_pool_cursor(conn.cursor())def test_with_pandas():with connection_pool().connection() as conn:df = pd.read_sql('SELECT * FROM user', conn)print(df)def delete_users():with connection_pool().cursor() as cursor:cursor.execute('TRUNCATE user')def add_users(users, conn):def execute(c):c.cursor().executemany('INSERT INTO user (name, age) VALUES (%s, %s)', users)c.commit()if conn:execute(conn)returnwith connection_pool().connection() as conn:execute(conn)def add_user(user, conn=None):def execute(c):c.cursor().execute('INSERT INTO user (name, age) VALUES (%s, %s)', user)c.commit()if conn:execute(conn)returnwith connection_pool().connection() as conn:execute(conn)def list_users():with connection_pool().cursor() as cursor:cursor.execute('SELECT * FROM user ORDER BY id DESC LIMIT 5')print('...')for x in sorted(cursor, key=lambda d: d['id']):print(x)def random_user():name = "".join(random.sample(string.ascii_lowercase, random.randint(4, 10))).capitalize()age = random.randint(10, 40)return name, agedef worker(id_, batch_size=1, explicit_conn=True):print('[{}] Worker started...'.format(id_))def do(conn=None):for _ in range(batch_size):add_user(random_user(), conn)if not explicit_conn:do()returnwith connection_pool().connection() as c:do(c)print('[{}] Worker finished...'.format(id_))def bulk_worker(id_, batch_size=1, explicit_conn=True):print('[{}] Bulk worker started...'.format(id_))def do(conn=None):add_users([random_user() for _ in range(batch_size)], conn)time.sleep(3)if not explicit_conn:do()returnwith connection_pool().connection() as c:do(c)print('[{}] Worker finished...'.format(id_))def test_with_single_thread(batch_number, batch_size, explicit_conn=False, bulk_insert=False):delete_users()wk = worker if not bulk_insert else bulk_workerfor i in range(batch_number):wk(i, batch_size, explicit_conn)list_users()def test_with_multi_threads(batch_number=1, batch_size=1000, explicit_conn=False, bulk_insert=False):delete_users()wk = worker if not bulk_insert else bulk_workerthreads = []for i in range(batch_number):t = threading.Thread(target=wk, args=(i, batch_size, explicit_conn))threads.append(t)t.start()[t.join() for t in threads]list_users()if __name__ == '__main__':import timestart = time.perf_counter()test_pool_cursor()test_pool_connection()test_with_pandas()test_with_multi_threads(20, 10, True, bulk_insert=True)test_with_single_thread(1, 10, True, bulk_insert=True)elapsed = time.perf_counter() - startprint('Elapsed time is: "{}"'.format(elapsed))

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/495152.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

大型JavaScript应用程序架构模式

http://www.cnblogs.com/TomXu/archive/2011/12/14/2286225.html转载于:https://www.cnblogs.com/aaa6818162/archive/2012/02/03/2337242.html

Python 定时任务框架 apscheduler

github 地址:https://github.com/agronholm/apscheduler apscheduler 基本概念介绍 说到定时任务,会想起 linux 自带的 crontab ,windows 自带的任务计划,都可以实现守时任务。操作系统基本都会提供定时任务的实现,但是…

一文看懂人工智能产业链,未来10年2000亿美元市场

来源:传感器技术摘要:据腾讯研究院统计,截至2017年6月,全球人工智能初创企业共计2617家。美国占据1078家居首,中国以592家企业排名第二,其后分别是英国,以色列,加拿大等国家。根据艾…

Griview中的删除按钮添加“确认提示”

<ItemTemplate><asp:LinkButton ID"LinkButton1" runat"server" CausesValidation"false"CommandName"dele" Text"删除" CommandArgument<%#Eval("EmpNo") %> OnClientClick"return confirm…

如何跟机器人“抢”工作?专家:新的分工将形成

来源&#xff1a;经济日报摘要&#xff1a;随着人工智能技术的深度发展和机器人的广泛应用&#xff0c;人们会从许多传统生产活动中解放出来&#xff0c;有了更多闲暇时间&#xff0c;更强大的支持手段&#xff0c;让生活更有趣和丰富多彩。创新、创意会成为生活和工作中的必需…

hwnd = 0 各种粗心大意啊!

一个简单的对话框程序。运行后出了错误&#xff0c;m_pMainWndNULL了。 CDInputTestDlg dlg; m_pMainWnd &dlg; 百思不得其解&#xff0c;后来终于发现在自己写的一个类的构造函数中。 由于下面一行从上面一行复制过来&#xff0c;只改了前面的参数忘了后面的&#xff0c;…

Scrapy 爬虫教程导航

From&#xff1a;https://brucedone.com/archives/771 8个最高效的 Python 爬虫框架 1. Scrapy。Scrapy是一个为了爬取网站数据&#xff0c;提取结构性数据而编写的应用框架。2. PySpider。pyspider 是一个用python实现的功能强大的网络爬虫系统&#xff0c;能在浏览器界面上进…

手指甲上的月牙辨健康,月牙会“丢”也能“长回来”

我以前指甲上只有两个小月牙&#xff0c;都是在大拇指上的。后来听一些姐妹说这是气虚血弱的表现。。。于是我就去问我们楼下80多岁的老中医&#xff08;嘿嘿&#xff01;他和我关系可好了&#xff09;&#xff0c;这位老中医以前是我们这边省中医院内科的专家&#xff0c;退休…

互联网让我们变笨了吗:过去10年关于大脑的11个有趣发现

来源&#xff1a;资本实验室摘要&#xff1a;人类大脑&#xff0c;长期以来被认为科学和宇宙中最复杂的事物之一。鉴于其复杂性&#xff0c;受制于技术限制&#xff0c;过去科学家很难解开其内部运作的秘密&#xff0c;但目前的研究成果表明我们离秘密又近了一些。聚焦前沿科技…

消息中间件 --- Kafka快速入门

消息中间件 --- Kafka 快速入门 消息中间件&#xff1a;https://blog.51cto.com/u_9291927/category33 GitHub: GitHub - scorpiostudio/HelloKafka: HelloKafka Kafka快速入门&#xff08;一&#xff09;--- Kafka简介&#xff1a;https://blog.51cto.com/9291927/2493953Kaf…

asp.net中jQuery $post用法

函数原型&#xff1a;$.post(url, params, callback) url是提交的地址&#xff0c;eg&#xff1a; "sample.ashx" params是参数&#xff0c;eg&#xff1a; { name:"xxx" , id:"001" } callback是回调函数&#xff0c;eg&#xff1a; function…

美研究人员公布“盲动”机器人技术细节

来源&#xff1a;新华网摘要&#xff1a;&#xff17;月&#xff17;日美国麻省理工学院近日发布公报称&#xff0c;该校研究人员最新公布了一种“盲动”机器人的技术细节。这种机器人不需要借助视觉系统&#xff0c;可在崎岖地形中穿行跳跃&#xff0c;有望在危险工作环境中得…

使IE6下PNG背景图片透明的七种方法

PNG图像格式介绍&#xff1a; PNG是20世纪90年代中期开始开发的图像文件存储格式&#xff0c;其目的是企图替代GIF和TIFF文件格式&#xff0c;同时增加一些GIF文件格式所不具备的特性。流式 网络图形格式(Portable Network Graphic Format&#xff0c;PNG)名称来源于非官方的“…

AutoJs 4.1.1 实战教程

Auto.js 中文文档&#xff1a;https://hyb1996.github.io/AutoJs-Docs/#/?id综述 pro 版本支持 Node.js AutoJs Pro 7.0.4-1 实战教程---史上最全快手、抖音极速版 &#xff1a;https://blog.csdn.net/zy0412326/article/details/107180887/&#xff1a;https://blog.csdn.n…

人工智能军备竞赛:一文尽览全球主要国家AI战略

来源&#xff1a;网络大数据摘要&#xff1a;人工智能的迅速发展将深刻改变人类社会和世界的面貌&#xff0c;为了抓住 AI 发展的战略机遇&#xff0c;越来越多的国家和组织已争相开始制定国家层面的发展规划。人工智能的迅速发展将深刻改变人类社会和世界的面貌&#xff0c;为…

EJB3与EJB2的差别

1、Annotation替代了配置文件   凡是EJB2中使用配置文件定义的&#xff1b;EJB3一般都可以使用 annotations定义&#xff08;当然EJB3也支持配置文件定义&#xff09;&#xff1b;   凡是EJB2通过JNDI寻找的资源&#xff08;调用容器中其他EJB、调用环境变量等Resource资源…

Android 读取、接收、发送 手机短信

&#xff1a;https://www.cnblogs.com/ycclmy/tag/android/ 1、Android 读取手机短信 From&#xff1a;https://www.cnblogs.com/ycclmy/p/3193075.html 获取 android 手机短信需要在 AndroidManifest.xml 加权限&#xff1a; <uses-permission android:name"android.…

flex和js进行参数传递

来着&#xff1a;http://www.cnblogs.com/Cnol/archive/2009/09/20/1570365.html 方法一&#xff1a;flex接收网页传值&#xff01;~ 1<?xml version"1.0" encoding"utf-8"?> 2<mx:Application xmlns:mx"http://www.adobe.com/2006/mxml&q…

师法自然,仿生技术是如何改变世界的?

来源&#xff1a;36Kr摘要&#xff1a;“向自然学习”&#xff0c;这并非是句空话。本文介绍了科学家如何借鉴大自然&#xff0c;在材料科学&#xff0c;信息技术等领域实现创新。希望能为您带来启发。当今世界最伟大的创新者&#xff0c;非大自然莫属。大自然经过45亿年的演变…

Auto.JS 开发

From&#xff1a;https://blog.csdn.net/a6892255/article/details/107302369 autojs 代码大全(实战演练)&#xff1a;https://blog.csdn.net/qq_30931547/article/details/106459765 &#xff1a;https://github.com/snailuncle/autojsCommonFunctions/blob/master/autojsCo…