图片验证吗是数字的情况
实现方式直接暴力破解循环写入就行
from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait import time class CrackSlider(object): """ 通过浏览器截图,识别验证码中缺口位置,获取需要滑动距离,并模仿人类行为破解滑动验证码 """ def __init__(self): self.url = 'http://locahost:8080/' self.driver = webdriver.Chrome() self.wait = WebDriverWait(self.driver, 20) self.zoom = 1 def open(self): self.driver.get(self.url) def longin_info(self): time.sleep(52200) # 时间是秒 到达指定时间自动执行 self.driver.maximize_window() # 输入账号密码 self.driver.find_element_by_id("loginname").send_keys("admin") self.driver.find_element_by_id("password").send_keys("123456") for i in range(-10, 100): self.driver.find_element_by_id('code').clear() self.driver.find_element_by_id('code').send_keys(i) time.sleep(1) # 点击登陆 self.driver.find_element_by_id("to-recover").click() time.sleep(5) try: su = self.driver.find_element_by_xpath("//*[contains(@class,'alert alert-block alert-success')]") if su == '欢迎使用 OA SYSTEM 系统': print("登陆成功") break except: print("登陆失败") if __name__ == '__main__': cs = CrackSlider() cs.open() cs.longin_info()