0.关键实现:程序窗口前置

python 通过js控制滚动条拉取全文 通过psutil获取pid窗口句柄,通过win32gui使程序窗口前置 通过pyauto实现右键菜单和另存为操作

1.参考

  • autopy (实践见最后一章节)

用Python制作游戏外挂(上)

AutoPy Introduction and Tutorial

autopy.mouse.smooth_move(1, 1) 可以实现平滑移动

autopy — API Reference

  • pip install PyUserInput

SavinaRoja/PyUserInput

[python3.5][PyUserInput]模拟鼠标和键盘模拟

Python-模拟鼠标键盘动作

  • autoit

selenium借助AutoIt识别上传(下载)详解

selenium webdriver 右键另存为下载文件(结合robot and autoIt)

  • win32api

Python实现windows下模拟按键和鼠标点击的方法

用Python模拟键盘输入

  • pyautowin

https://pyautogui.readthedocs.io/en/latest/

  • 其他PyAutoGUI等。。。

python 模拟键盘鼠标输入

PyAutoGUI-python版的autoit/AHK

2.下载地址

http://www.ghost-mouse.com/

https://en.uptodown.com/windows/automatization  >>  https://tinytask.en.uptodown.com/windows

https://www.autoitscript.com/site/autoit/downloads/

3.工具简介

(1)GhostMouse导出文件可读,可以通过脚本提取鼠标轨迹和键盘输入内容。但是通过命令行运行所导出的文件,只是自动打开程序,还需要通过快捷键运行回放。

(2)tinytask导出文件不可读,可以导出编译好的exe,通过命令行可以直接无界面回放。

Python模块学习:subprocess 创建子进程

Python执行系统命令,os.system && os.popen && subprocess.Popen

4.python调用外部脚本或程序(如tinytask)

import subprocess
def run_tinytask(rec_file_compiled):
# 运行外部脚本,传入参数和接受print内容
# p = subprocess.Popen(['python','xxx.py','-n',sth_to_pass],stdout=subprocess.PIPE)
# result = p.stdout.read() # 参考pytesseract.py
command = [rec_file_compiled]
# proc = subprocess.Popen(command, stderr=subprocess.PIPE)
proc = subprocess.Popen(command)
status = proc.wait()
# error_string = proc.stderr.read()
# proc.stderr.close()
# print status, error_string
return status def main():
rec_file_compiled = 'G:/pydata/install/test.exe' # tinytask导出的编译文件
print run_tinytask(rec_file_compiled)
print 'finished' if __name__ == '__main__':
main()

5.通过脚本提取GhostMouse记录的鼠标轨迹和键盘输入内容

(1)参考

滑动验证码破解:Python Selenium 2.0 应用

(2)代码实现

#coding:utf-8

# GhostMouse导出的rms文件
# {Delay 2.13}
# {Move (1225,349)}
# {Delay 0.23} # {Move (729,657)}
# {Delay 1.65}
# {LMouse down (727,658)} #鼠标按下开始拖动
# {Delay 0.99}
# {Move (727,658)}
# {Delay 0.11} # {Move (790,659)}
# {Delay 0.91}
# {LMouse up (790,659)} #鼠标释放结束拖动 import os # xyd_typical = (1,0,0.04)
def read_rms(file_rms): with open(file_rms) as fp: #os.path.sep
LMouse_down = False for line in fp:
#{LMouse down (727,658)}
# {Delay 1.65}
if 'LMouse down' in line or (LMouse_down == True and 'Move' in line):
if 'LMouse down' in line:
LMouse_down = True
xyd_records = []
x_last, y_last = 0, 0 #保证第一个偏移量为实际开始位置
xy_pos = line.split('(')[1].split(')')[0].split(',')
x_pos, y_pos = [int(i) for i in xy_pos]
continue
# {Move (729,657)}
# {Delay 1.65}
if LMouse_down == True and 'Delay' in line:
x_delta, y_delta = x_pos-x_last, y_pos-y_last
if x_delta == 0 and y_delta == 0 and len(xyd_records) != 0: #len 可能起点就是0,0
continue
else:
delay = float(line.split(' ')[1].split('}')[0])
xyd_records.append((x_delta, y_delta, delay))
x_last, y_last = x_pos, y_pos
continue # {LMouse up (790,659)}
if LMouse_down == True and 'LMouse up' in line:
# x_init y_init x_change y_change
# x y d 每一次偏移量
# x y d
with open(file_txt,'a') as fh_txt:
# x_change = sum(x for x,y,d in xyd_records)
x_init = xyd_records[0][0]
y_init = xyd_records[0][1]
x_change = sum(x for x,y,d in xyd_records[1:])
y_change = sum(y for x,y,d in xyd_records[1:])
fh_txt.write('{} {} {} {}\n'.format(x_init, y_init, x_change, y_change)) #加os.linesep是'\r\n'
for x,y,d in xyd_records[1:]: #第一个记录为起始位置,value记录之后的每一次偏移
fh_txt.write('{} {} {}\n'.format(x, y, d))
LMouse_down = False
xyd_records = [] def read_txt(file_txt):
with open(file_txt,'r') as fp:
result = {} #(x_init, y_init, x_change, y_chang): [(x0,y0,d0), (x1,y1,d1)...] for line in fp:
line = line.strip().split()
if len(line) == 4:
key = tuple([int(i) for i in line])
result[key] = []
elif len(line) == 3:
x,y,d = line
x,y,d = int(x), int(y), float(d)
result[key].append((int(x), int(y), float(d)))
return result if __name__ == '__main__': file_rms = os.path.join(os.path.abspath('.'),'mouse.rms')
file_txt = os.path.join(os.path.abspath('.'),'mouse.txt')
read_rms(file_rms)
result = read_txt(file_txt)
for k,v in result.items():
print k,v

6.selenium+autopy实现右键另存为

#!/usr/bin/env python
# -*- coding: UTF-8 -*
import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
# import autopy
from autopy import key, mouse driver = webdriver.Chrome()
# driver = webdriver.Firefox() driver.get('http://www.baidu.com')
# <a class="mnav" href="http://news.baidu.com" name="tj_trnews">新闻</a>
e = driver.find_element_by_partial_link_text(u'新闻') #页面显示的链接文字,而不是具体链接地址,所以'news'不行!!!
# e = driver.find_element_by_name('tj_trnews') # fifefox geckodriver context_click异常
# https://stackoverflow.com/questions/6927229/context-click-in-selenium-2-2
# http://bbs.csdn.net/topics/392058306
# https://stackoverflow.com/questions/40360223/webdriverexception-moveto-did-not-match-a-known-command ActionChains(driver).context_click(e).perform()
# ActionChains(driver).move_to_element(e).context_click(e).perform() #也行
# mouse.click(mouse.RIGHT_BUTTON)
time.sleep(1.5)
key.type_string('k')
time.sleep(1.5)
key.type_string(time.strftime('%H%M%S'))
key.tap(key.K_RETURN)

python模拟鼠标键盘操作 GhostMouse tinytask 调用外部脚本或程序 autopy右键另存为的更多相关文章

  1. python模拟鼠标拖动操作的方法

    本文实例讲述了python模拟鼠标拖动操作的方法.分享给大家供大家参考.具体如下: pdf中的书签只有页码,准备把现有书签拖到一个目录中,然后添加自己页签.重复的拖动工作实在无趣,还是让程序帮我实现吧 ...

  2. 将CodedUI Test 放到控制台程序中,模拟鼠标键盘操作

    CodedUI Test是微软的自动化测试工具,在VS中非常好用.可以用来模拟鼠标点击,键盘输入.但执行的时候必须要用mstest调用,无法传入参数(当然可以写入config文件中,但每次修改十分麻烦 ...

  3. selenium webdriver从安装到使用(python语言),显示等待和隐性等待用法,切换窗口或者frame,弹框处理,下拉菜单处理,模拟鼠标键盘操作等

    selenium的用法 selenium2.0主要包含selenium IDE 和selenium webDriver,IDE有点类似QTP和LoadRunner的录制功能,就是firefox浏览器的 ...

  4. python selenium鼠标键盘操作(ActionChains)

    用selenium做自动化,有时候会遇到需要模拟鼠标操作才能进行的情况,比如单击.双击.点击鼠标右键.拖拽等等.而selenium给我们提供了一个类来处理这类事件--ActionChains sele ...

  5. selenium模拟鼠标键盘操作

    简单操作: 1.点击(鼠标左键)页面按钮:click() 2.清空输入框:clear() 3.输入字符串:send_keys()submit提交表单: 1.一般情况可以点击搜索按钮来搜索 2.也可以用 ...

  6. selenium webdriver(4)---模拟鼠标键盘操作

    webdriver提供Actions来模拟鼠标悬浮.拖拽和键盘输入等操作,详细代码见org.openqa.selenium.interactions.Actions.本文通过几个实例来说明Action ...

  7. Java+selenium之WebDriver模拟鼠标键盘操作(六)

    org.openqa.selenium.interactions.Actions类,主要定义了一些模拟用户的鼠标mouse,键盘keyboard操作.对于这些操作,使用 perform()方法进行执行 ...

  8. selenium webdriver模拟鼠标键盘操作

    在测试使用Selenium webdriver测试WEB系统的时候,用到了模拟鼠标.键盘的一些输入操作. 1.鼠标的左键点击.双击.拖拽.右键点击等: 2.键盘的回车.回退.空格.ctrl.alt.s ...

  9. selenuim2模拟鼠标键盘操作

    有时候有些元素不便点击或者做其他的操作,这个时候可以借助selenium提供的Actions类,它可以模拟鼠标和键盘的一些操作,比如点击鼠标右键,左键,移动鼠标等操作.对于这些操作,使用perform ...

随机推荐

  1. Linux查看文件以及磁盘空间大小管理(转)

    (1)查看文件大小  查看当前文件夹下所有文件大小(包括子文件夹)    du -sh   # du -h15M     ./package16K     ./.fontconfig4.0K    . ...

  2. mongoDB 文档操作_查

    基本查询命令 find 查找复合条件的所有文档 命令 db.collection.find(query,field) 参数 query 查找条件 格式: {ssss:"xxx"}是 ...

  3. CentOS配置history记录每个用户执行过的命令

    一个偶然的机会,看到了这个文档,先存下来,后续使用的话直接就加进去了 要记录登录者的用户名.IP.操作记录,在/etc/bashrc末尾加入几个环境变量,用于history命令显示用户ip等内容,完成 ...

  4. elastalert 配置post告警方式(备忘)

      最近在做把elk告警日志发送到kinesis 流,供后续数据分析处理使用........ 基于尽量不修改elastalert ,把修改工作放到接收端服务的原则.计划把elk的告警数据通过远程api ...

  5. idea搭建springboot

     1.创建新项目 2.继续项目配置 Name:项目名称Type:我们是Maven构建的,那么选择第一个Maven ProjectPackaging:打包类型,打包成Jar文件Java Version: ...

  6. null引用,有时候是实现了父类的方法,方法体没写任何实现

    null引用,有时候是实现了父类的方法,方法体没写任何实现 /* @Override public void attachView(MonthListContract.View view) { } * ...

  7. BIOS翻译

    BIOS翻译 BIOS(Basic Input/Output System—基本输入输出系统).BIOS可以视为是一个永久地记录在ROM中的一个软件 Main主要信息 :main 主要信息 advan ...

  8. DirectX11 With Windows SDK--06 DirectXMath数学库

    前言 xnamath.h原本是位于DirectX SDK的一个数学库,但是现在Windows SDK包含的数学库已经抛弃掉原来的xnamath.h,并演变成了现在的DirectXMath.h.其实本质 ...

  9. HDU 1584(蜘蛛牌 DFS)

    题意是在蜘蛛纸牌的背景下求 10 个数的最小移动距离. 在数组中存储 10 个数字各自的位置,用深搜回溯的方法求解. 代码如下: #include <bits/stdc++.h> usin ...

  10. SpringBoot系列: RestTemplate 快速入门

    ====================================相关的文章====================================SpringBoot系列: 与Spring R ...