#!/usr/bin/env python
--coding:utf-8--
import time import pytesser3 from selenium import webdriver from selenium.webdriver.common.keys import Keys import selenium.webdriver.support.ui as ui from selenium.webdriver.common.action_chains import ActionChains from PIL import Image,ImageEnhance from pymouse import PyMouse from pykeyboard import PyKeyboard
time.sleep(1) browser = webdriver.Firefox() browser.get('URL/') eles = browser.find_element_by_name("username") eles.send_keys("user") elem = browser.find_element_by_name("password") elem.send_keys("passwd")
browser.get_screenshot_as_file('D:/pic/image1.png') # 比较好理解 im = Image.open('D:/pic/image1.png') box = (941, 600, 1095, 650) # 设置要裁剪的区域 region = im.crop(box) # 此时,region是一个新的图像对象。 region.save("D:/pic/image_code.png") im = Image.open("D:/pic/image_code.png") imgry = im.convert('L') # 图像加强,二值化 sharpness = ImageEnhance.Contrast(imgry) # 对比度增强 sharp_img = sharpness.enhance(2.0) sharp_img.save("D:/pic/image_code1.png") im = Image.open('D:/pic/image_code1.png') im.show() SecretCode = input('please enter the code: ') elem = browser.find_element_by_name("verifyCode") elem.send_keys((SecretCode)) elem.send_keys(Keys.ENTER) browser.maximize_window() #mop自动修改 time.sleep(3) k = PyKeyboard() m = PyMouse() m.click(72, 411) #点击运单查询 time.sleep(1) m.click(84, 623) #点击MOP异常处理 time.sleep(3) m.click(377, 275) #点击下单开始时间 time.sleep(1) m.click(350, 308) #前选一年 time.sleep(1) m.click(486, 383) #确定 #开始循环点击,定义数组 a=("080927107021",
)
for y in a: m.click(357, 309) time.sleep(1) k.press_keys([k.control_l_key, 'a']) time.sleep(1) k.tap_key(k.delete_key) time.sleep(1) k.type_string((y)) m.click(257, 343) time.sleep(2) m.click(248, 575) time.sleep(2) m.click(1731, 578) time.sleep(2) m.click(465, 348) time.sleep(3) m.click(1036, 610) time.sleep(1)