from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import pytesseract
from PIL import Image
import time
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('http://202.199.100.156/jsxsd/')
driver.implicitly_wait(20)
driver.save_screenshot('yanzhengma.png')
photo = driver.find_element_by_id('SafeCodeImg')
location = photo.location
driver.find_element_by_id('userAccount').send_keys('171002101')
driver.find_element_by_id('userPassword').send_keys('********')
size = photo.size
rangle = (int(location['x']), int(location['y']), int(location['x'] + size['width']), int(location['y'] + size['height']))
time.sleep(3)
当然,验证码是个难题/(ㄒoㄒ)/~~,这里找到了验证码元素的位置,并获取他的位置,储存到range中
接下来在对刚才截屏的图片将验证码抠出来,再进行识别,妙啊
img = Image.open('yanzhengma.png')
cut = img.crop(rangle)
cut.save('yanzhengma.png')
NUMBER = pytesseract.image_to_