標籤:應用 sdn else move sub tor usr tde install
1.參考
用Python製作遊戲外掛(上)
AutoPy Introduction and Tutorial
autopy.mouse.smooth_move(1, 1) 可以實現平滑移動
autopy — API Reference
SavinaRoja/PyUserInput
[python3.5][PyUserInput]類比滑鼠和鍵盤類比
Python-類比滑鼠鍵盤動作
selenium藉助AutoIt識別上傳(下載)詳解
selenium webdriver 右鍵另存新檔下載檔案(結合robot and autoIt)
Python實現windows下類比按鍵和滑鼠點擊的方法
用Python類比鍵盤輸入
https://pyautogui.readthedocs.io/en/latest/
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 subprocessdef 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 statusdef 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 timefrom selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChains# import autopyfrom autopy import key, mousedriver = 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-commandActionChains(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右鍵另存新檔