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安装 示 ...
随机推荐
- 12c R2 RAC Oracle Linux 7.3 ESXI6.5
环境:ESXI6.5虚拟化 主机配置:操作系统 Oracle Linux 7.3 CPU:8个VCPU 内存:16G 本地磁盘:50G 全程默认最小化安装Oracle Linux 7.3操作系统 每个 ...
- [转]在Eclipse中搭建Python开发环境
在Eclipse中搭建Python开发环境 来自: http://hi.baidu.com/hqwfreefly/blog/item/2543181d0afd9604314e150e.html 前言 ...
- WEKA结果解读
红括号里面,左边是bad的数目,右边是good数目. TP Rate FP Rate Precision Recall F-Measure ROC Area Class 0.536 ...
- influxDB 0.9 C# 读写类
influxDB 0.9 C# 读写类 目前influxdb官网推荐的C#读写类是针对0.8版本的,截至本文写作之前,尚未发现有针对0.9的读写类. 我使用influxdb的是用于保存服务器的运行 ...
- html多个水平并列组件自适应等高的做法
做一个div盒子,设置over-flow:hidden,设置高度为auto.然后再盒子里排列若干inline-block,inline元素. 自适应的话常用做法是用line-height,font-s ...
- camtasis studio 未能创建视频内存资源。
camtasis studio failed to create a video memory resource.camtasis studio 未能创建视频内存资源. 在工具--选项中取消GPU加速 ...
- win2008 server 多IP配置
本人服务器环境 win8 + phpstudy 一个服务器多个IP 以前都是用linux,买了几套源码结果都是win8server 服务器+phpstudy. 渐渐也就随大流了.懒的去琢磨 一 ...
- 30 个java编程技巧(最佳实践的初学者)
1.return 一个空的集合,而不是 null 如果一个程序返回一个没有任何值的集合,请确保一个空集合返回,而不是空元素.这样你就不用去写一大堆 ”if else” 判断null元素. Java 的 ...
- [蓝桥杯]ALGO-51.算法训练_Torry的困惑(基本型)
题目描述: 问题描述 Torry从小喜爱数学.一天,老师告诉他,像2...……这样的数叫做质数.Torry突然想到一个问题,前10...……个质数的乘积是多少呢?他把这个问题告诉老师.老师愣住了,一时 ...
- Ubuntu 14.10 下安装伪分布式hdoop 2.5.0
折腾了一天,其间配置SSH时候出现了问题,误删了ssh-keygen相关文件,导致配置SSH彻底萎了,又重装了系统.... 采用伪分布式模式,即hadoop将所有进程运行于同一台主机上,但此时Hado ...