创建浏览器驱动对象
加载登录页面
等待页面加载完毕
切换到用户名和密码登录模式
输入手机号,注意此处需要等待并获取输入框
输入密码
点击验证按钮
获取弹出验证图片
使用超级鹰打码平台识别图形的坐标
获取到坐标信息,x, y坐标分别除以2;由于电脑分辨率太过了,是原来的两倍,如果是普通分辨率可以除以2,直接用就可以了。
把鼠标移动到,坐标点的位置进行点击
点击登录按钮
从硒进口webdriver 从selenium.webdriver.common.by进口 从selenium.webdriver.support。ui进口WebDriverWait 从selenium.webdriver。支持导入expected_conditions EC 从硒。webdriver进口ActionChains 导入的时间 #导入超级鹰 从chaojiying进口chaojiying #根据系统,可能截图不成功,需要使用无头浏览,mac系统可以不设置 选择=webdriver.ChromeOptions () options.headless=True 司机=webdriver.Chrome(选项=药水) driver.get (“http://www.zhaopingou.com/signin”) driver.find_element_by_class_name (li02) .click () 等待=WebDriverWait(司机,20日,0.5) #账号登录 login_phone=wait.until (EC.visibility_of_element_located ((By.ID, pwd_login_phone))) login_phone.send_keys (“17724035140”) #密码 driver.find_element_by_id (form_login_password) .send_keys (“961831740 hzll”) #点击获取图片 验证码=wait.until (EC.visibility_of_element_located ((。XPATH,//div [@class=" phone_login_pwd "]//iframe(始于(@ id, captcha_widget)] "))) captcha.click () #点击 #保存图片(可以不保存) captcha_element=wait.until (EC.visibility_of_element_located ((。XPATH,//身体[@class=" graybc "]//iframe(始于(@ id, captcha_frame)] "))) captcha_element.screenshot (“zhaopingou.png”) #将图片转换为二进制 bytes_img=captcha_element.screenshot_as_png #打印(bytes_img) 结果=chaojiying.post_pic (bytes_img,‘9101’) x, y=结果[' pic_str '] .split (" ") print (x, y) x=int (x) int y=(y) # ActionChains(司机).move_to_element_with_offset (bytes_img, x, y) .click () .perform () ActionChains(司机)。move_to_element_with_offset (captcha_element, x, y) .click () .perform () time . sleep (2) driver.find_element_by_id (free_login_btn) .click () 打印(driver.window_handles) driver.switch_to.window (driver.window_handles [0]) # time . sleep (5) driver.quit () >之前以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
Python点击指定位置验证码破解的实现代码