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安装 示 ...
随机推荐
- 基于geohash6编码实现相邻4、9、16网格合并
前面的两篇文章介绍了geohash的基本原理及c#代码相关实现,其中geohash 5位编码单个网格覆盖面积大约在24平方千米,6位编码单网格覆盖面大约在0.73平方千米, 相邻编码长度之间单网格覆盖 ...
- messageBox 的几种显示方式
1.最简单的,只显示提示信息 MessageBox.Show("Hello~~~~"); 2. 可以给消息框加上标题. MessageBox.Show("There ar ...
- Hiero的spreadsheet中添加tag属性列
Hiero在对剪辑线上的item进行管理的时候,往往会添加能多tag,而在管 理面板spreadsheet中却无法对tag进行查询,这是一件很麻烦的事,Hiero Development Guide中 ...
- VS2012打开项目——已停止工作
VS2012打开项目——已停止工作 解决方法如下: 1. 开始-->所有程序-->Microsoft Visual Studio 2012-->Visual Studio Tools ...
- MySQL 单条记录长度最大65535
今天设计表结构,加了几个字段,结果报错了 Ligne trop grande. Le taille maximale d'une ligne, sauf les BLOBs, est 65535... ...
- Java课程设计(2019版)
参考资料 Java课程设计参考资料(2018-12-26更新) Java课程设计常见问题(程序部署.数据库.JSP) 项目开发参考-阿里巴巴Java开发手册(正式版) 更多参考资料请查看QQ群文件中的 ...
- 在64位平台上的Lucene,应该使用MMapDirectory[转]
http://blog.thetaphi.de/2012/07/use-lucenes-mmapdirectory-on-64bit.html 从3.1版本开始,Lucene和Solr开始在64位的W ...
- (转载)关于java多线程web服务器 以及相关资料转载
1.自己实现的简单的java多线程web服务器: https://blog.csdn.net/chongshangyunxiao321/article/details/51095149 自己实现一个简 ...
- vuex状态管理2
在vuex的官网https://vuex.vuejs.org中,提到的核心概念一共有5个,分别是State.Getter.Mutation.Action和Module,在上一篇随笔中,我们主要用到其中 ...
- Scrapy学习篇(二)之常用命令行工具
简介 Scrapy是通过Scrapy命令行工具进行控制的,包括创建新的项目,爬虫的启动,相关的设置,Scrapy提供了两种内置的命令,分别是全局命令和项目命令,顾名思义,全局命令就是在任意位置都可以执 ...