Open shownb opened 5 years ago
Python+selenium针对wy控件过登录取数据 https://sbcoder.cn/2019/03/21/Python_WY_Spider.html
selenium登录wy,密码控件输入 https://www.cnblogs.com/6min/p/10868825.html
wy安全控件问题 https://www.cnblogs.com/davidwang456/articles/8708479.html
winio install like that https://www.jianshu.com/p/4cb399f31ec9
win7 32安装 https://www.microsoft.com/zh-TW/download/details.aspx?id=47352
pip install pywinio证书有问题。先更新requests, pip install requests
# _*_ coding: utf-8 _*_
import os, sys
import uuid, time
import pytesseract
from selenium import webdriver
from ctypes import windll
from PIL import Image
def tesseract_file(file_path):
#my_env = {'TESSDATA_PREFIX': r'C:\Program Files\Tesseract-OCR\testdata'}
image = Image.open(os.path.realpath(file_path))
result = pytesseract.image_to_string(image)
return result
def login_abc(param):
url = 'https://perbank.abchina.com/EbankSite/startup.do'
ie_driver = 'C:\Program Files\Internet Explorer\IEDriverServer.exe'
#os.environ["webdriver.ie.driver"] = ie_driver
browser = webdriver.Ie(ie_driver)
browser.maximize_window()
browser.get(url)
time.sleep(1)
browser.find_element_by_id('username').send_keys(param['username'])
#载入DD
libpath = 'libs/DD81200x32.dll' if sys.platform == 'win32' else 'libs/DD81200x64.32.dll'
dd_dll = windll.LoadLibrary(libpath)
vk = {'5': 205, 'c': 503, 'n': 506, 'z': 501, '3': 203, '1': 201, 'd': 403, '0': 210, 'l': 409, '8': 208,
'w': 302,
'u': 307, '4': 204, 'e': 303, '[': 311, 'f': 404, 'y': 306, 'x': 502, 'g': 405, 'v': 504, 'r': 304,
'i': 308,
'a': 401, 'm': 507, 'h': 406, '.': 509, ',': 508, ']': 312, '/': 510, '6': 206, '2': 202, 'b': 505,
'k': 408,
'7': 207, 'q': 301, "'": 411, '\\': 313, 'j': 407, '`': 200, '9': 209, 'p': 310, 'o': 309, 't': 305,
'-': 211,
'=': 212, 's': 402, ';': 410}
#需要组合shift的按键。
vk2 = {'"': "'", '#': '3', ')': '0', '^': '6', '?': '/', '>': '.', '<': ',', '+': '=', '*': '8', '&': '7',
'{': '[', '_': '-',
'|': '\\', '~': '`', ':': ';', '$': '4', '}': ']', '%': '5', '@': '2', '!': '1', '(': '9'}
def down_up(code):
dd_dll.DD_key(vk[code], 1)
dd_dll.DD_key(vk[code], 2)
def dd(key):
if i.isupper():
# 按下抬起 500是shift键码
dd_dll.DD_key(500, 1)
down_up(i.lower())
dd_dll.DD_key(500, 2)
elif i in '~!@#$%^&*()_+{}|:"<>?':
dd_dll.DD_key(500, 1)
down_up(vk2[i])
dd_dll.DD_key(500, 2)
else:
down_up(i)
img = browser.find_element_by_id('vCode')
x, y = img.location['x'] + 50, img.location['y'] + 50
#移动到密码框点击激活
dd_dll.DD_mov(x, y)
dd_dll.DD_btn(1)
time.sleep(1)
#依次输入密码字符
for i in param['password']:
dd(i)
time.sleep(0.2)
left, top = img.location['x'], img.location['y']
width, height = img.size['width'] + left, img.size['height'] + top
os.makedirs('imgs')
oldpath = 'imgs/' + str(uuid.uuid1()) + '.png'
browser.save_screenshot(oldpath)
oldpic = Image.open(oldpath)
newpic = oldpic.crop((left, top, width, height))
picpath = 'imgs/' + str(uuid.uuid1()) + '.png'
newpic.save(picpath)
os.remove(oldpath)
#tesseract可以识别简单的图形验证码
vcode = tesseract_file(picpath)
browser.find_element_by_name('code').send_keys(vcode)
#os.remove(picpath)
browser.find_element_by_id('logo').click()
time.sleep(1)
logerr = browser.find_element_by_class_name('logon-error').text
print(logerr)
if __name__ == '__main__':
login_abc({'username':'13311111111', 'password':'123456'})
Selenium 调用IEDriverServer打开IE浏览器
参考链接 https://blog.csdn.net/jichuang123/article/details/53008581 大概是:
之后在key内部创建一个iexplorer.exe,DWORD类型,值为0
关于webdriver下载地址 http://selenium-release.storage.googleapis.com/index.html IEDriverServer_x64_3.14.0.zip http://selenium-release.storage.googleapis.com/3.14/IEDriverServer_x64_3.14.0.zip
Selenium XPATH 定位最全总结 https://testerhome.com/topics/20296
屏幕录取 被录取端
观看端