pyautogui控制鼠标键盘自动填写数据
import os
import pyautogui
import time, os
import pyperclip # 复制
pyautogui.FAILSAFE = False class Auto:
def get_xs(self, x_imgs):
"""
:param x_imgs: 用来确定表格x坐标的图片 路径列表
:return:
"""
xs = []
for img in x_imgs:
button7location = None
while not button7location:
button7location = pyautogui.locateOnScreen(img, grayscale=True)
if button7location:
x, _ = [i / 2 for i in pyautogui.center(button7location)]
xs.append(x)
else:
if img == x_imgs[0]:
return xs
return xs def to_find_page(self):
print('切换网页')
pyautogui.hotkey('ctrl', 'tab') # 切换网页
# pyautogui.hotkey('command', 'tab') # 切换网页
time.sleep(1)
return True def get_x_imgs(self, x_path):
abs_file = os.path.abspath('.')
if not abs_file.endswith('img'):
abs_file = os.path.join(abs_file, 'utils/img')
print(abs_file)
path = os.path.join(abs_file, x_path)
print(path)
# x_imgs = [f'utils/img/{x_path}/x1.png', f'utils/img/{x_path}/x2.png',
# f'utils/img/{x_path}/x3.png', f'utils/img/{x_path}/x4.png']
# x_imgs = [os.path.join(abs_file, i) for i in x_imgs]
l = os.walk(path)
x_imgs = []
for i, v, files in l:
for file in files:
if file.split('.')[0].startswith('x') and file.split('.')[-1] in ['png', 'jpeg']:
x_imgs.append(os.path.join(path, file))
return x_imgs def auto_write(self, xs, datas, x_path):
"""
:param xs: 表格每列的x坐标列表
:param datas: 需要填写的数据 {y1_2: 100} y1:代表第一行, 2:代表第二列, 100为填写的值
:param x_path: 文件夹名字(以表格名字为文件夹名)
:return:
"""
keys = datas.keys()
# yes = False
for key in keys:
name, index = key.split('_')
# file = f'utils/img/{x_path}/{name}.png'
file = f'{x_path}/{name}.png'
abs_file = os.path.abspath('.')
if not abs_file.endswith('img'):
abs_file = os.path.join(abs_file, 'utils/img')
file = os.path.join(abs_file, file)
button7location = None
while button7location is None:
button7location = pyautogui.locateOnScreen(file, grayscale=True, confidence=.8)
# 滚动条下滑
if not button7location:
# if not yes:
# return False
pyautogui.scroll(-1)
# yes = True
_, button7y = [i / 2 for i in pyautogui.center(button7location)]
print(key)
pyautogui.moveTo(xs[int(index)-1], button7y, duration=.1) pyautogui.click()
# pyautogui.click() # pyautogui.typewrite(str(datas[key]))
# 复制粘贴效果好点
# pyperclip.copy(datas[key]) # 先复制
# pyautogui.hotkey('command', 'v') # 再粘贴
return True def main(datas, table_name):
"""
:param datas:
:param table_name: 文件名=表名
:return:
"""
auto = Auto()
x_imgs = auto.get_x_imgs(x_path=table_name)
xs = None
n = 0
while not xs:
n += 1
print(f'n:{n}')
auto.to_find_page()
xs = auto.get_xs(x_imgs=x_imgs)
auto.auto_write(xs=xs, datas=datas, x_path=table_name) if __name__ == '__main__':
datas = {'y1_2': 1}
main(datas=datas, table_name='test')
pyautogui控制鼠标键盘自动填写数据的更多相关文章
- Python使用pyautogui控制鼠标键盘
官方文档:https://pyautogui.readthedocs.io/en/latest/# 安装pyautogui模块 在 Windows 上,不需要安装其他模块. 在 OS X 上,运行 s ...
- python,PyAutoGUI,设置鼠标键盘自动操作
三个文件需在同一个文件夹下面,文件夹的位置无要求. 1.第一个文件,trial.py.python代码调用PyAutoGUI操作鼠标键盘,可以通过修改start_time和end_time来确定程序自 ...
- python如何直接控制鼠标键盘
一.简介 我们知道在windows下输入:win + r,会弹出下面的窗口,而在下面的窗口出现后我们接着按下esc键,下面的窗口会消失 现在设想我们想在python代码里控制键盘,想通过运行代码-&g ...
- Python直接控制鼠标键盘
Python直接控制鼠标键盘 之前因为期末的原因已经很久没写博客了,今天博主发现一个好玩的模块PyAutoGUI,借助它可以使用Python脚本直接控制键盘鼠标,感觉可以解决很多无聊的机械运动.这里记 ...
- 安利下PyAUtoGUI这个库,可自动化控制鼠标键盘
PyAutoGUI 不知道你有没有用过,它是一款用Python自动化控制键盘.鼠标的库.但凡是你不想手动重复操作的工作都可以用这个库来解决. 比如,我想半夜时候定时给发个微信,或者每天自动刷页面等操作 ...
- Python——控制鼠标键盘
一.安装包 pip install pynput 二.引用包 from pynput import mouse,keyboard 三.控制鼠标 from pynput.mouse import But ...
- 用代码控制鼠标键盘(C#语言)
前些时间想做一个鼠标点击器,用到了这些知识. 下面整理记录一下. ps.感谢各位大神 下面直接上代码 1.鼠标的控制 class MouseMove { #region MouseEvent [Sys ...
- 【328】Python 控制鼠标/键盘+图片识别 综合应用
本文是基于 [267]实现跨网络传数据 的基础上的,由于在弹出 putty 之后,需要手动输入命令(pass.sh.get.sh)来实现数据的传递,另外就是处理完之后需要手动关闭 putty,本文解决 ...
- python 监视和控制鼠标键盘的输入(使用pynput 而非pyhook)
百度上搜到的文章大多基于pyhook, pip不能直接安装,托管在sourceForge上的代码仓库也找不到. google上发现可以使用pynput,貌似控制更为简单,而且可以直接使用pip安装 示 ...
随机推荐
- elasticsearch UNASSIGNED 处理
PUT /_settings HTTP/1.1 Host: 192.168.1.12:9200 Cache-Control: no-cache Postman-Token: 1befb0fb-6492 ...
- Thinkphp 3.1. 3 ueditor 1.4.3 添加水印
1.引入Ueditor <!-- 实例化编辑器 --> <script type="text/javascript"> window.UEDITOR_HO ...
- Azure ARM (15) 根据现有VHD文件,创建ARM VM
<Windows Azure Platform 系列文章目录> 在很多时候,我们需要根据现有VHD文件,创建ARM VM.在这里笔者简单介绍一下相关的Azure PowerShell 这里 ...
- linux svn客户端通过 https访问windows VisualSVN Server Manager
1)需求: 已经在阿里云windwos系统 下面安装了VisualSVN Server Manager 做为svn服务器: 现在要在腾讯云源码安装新版本客户端 2)开始源码编译安装TortoiseSV ...
- SELinux杂谈
----------------------------- 文末有推荐参考文档列表--------------------------- SELinux(Security Enhanced Linux ...
- 【linux】之常用命令-杂项
查看端口:lsof -i :80 二.内存大小[root@xbidc ~]# cat /proc/meminfo |grep MemTotalMemTotal: 1034612 kB[root@xbi ...
- STL进阶--删除元素
删除元素 从vector或deque删除元素 vector<int> vec = {1, 4, 1, 1, 1, 12, 18, 16}; // 删除所有的1 for (vector< ...
- RTMP与HLS压力测试工具安装与配置
在CentOS 6.5环境中安装依赖软件包,使用git下载最新版本st-load源码包 [root@localhost ~]# yum install git unzip patch gcc gcc- ...
- redis(redis概念,运用场景,如何操作基本数据类型)
什么是redis:Nosql一种缓存数据库 redis可以干什么:redis可以减轻对数据库的请求压力如果不使用缓存:客服端->控制层->业务层->dao层使用缓存:客服端-> ...
- 【ZZ】号称“开发者神器”的GitHub,到底该怎么用?
号称“开发者神器”的GitHub,到底该怎么用? https://mp.weixin.qq.com/s/zpKOBMKWckY05Mv_B28RgQ A developer’s introductio ...