Python 点击指定位置验证码破解的实现代码

yipeiwu_com5年前Python基础

思路:

创建浏览器驱动对象

加载登录页面

等待页面加载完毕

切换到用户名和密码登录模式

输入手机号, 注意此处需要等待并获取输入框

输入密码

点击验证按钮

获取弹出验证图片

使用超级鹰打码平台识别图形的坐标

获取到坐标信息, x,y坐标分别除以2; 由于电脑分辨率太过了, 是原来的两倍, 如果是普通分辨率可以除以2,直接用就可以了.

把鼠标移动到, 坐标点的位置进行点击

点击登录按钮

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains

import time
# 导入超级鹰
from chaojiying import chaojiying
#根据系统,可能截图不成功,需要使用无头浏览,mac系统可以不设置
options=webdriver.ChromeOptions()
options.headless=True

driver=webdriver.Chrome(options=potions)
driver.get('http://www.zhaopingou.com/signin')


driver.find_element_by_class_name('li02').click()
wait=WebDriverWait(driver,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('961831740hzll')
# 点击获取图片
captcha = wait.until(EC.visibility_of_element_located((By.XPATH, '//div[@class="phone_login_pwd"]//iframe[starts-with(@id, "captcha_widget")]')))
captcha.click()
# 点击
# 保存图片(可以不保存)
captcha_element = wait.until(EC.visibility_of_element_located((By.XPATH, '//body[@class="graybc"]//iframe[starts-with(@id, "captcha_frame")]')))
captcha_element.screenshot('zhaopingou.png')

# 将图片转换为二进制
bytes_img=captcha_element.screenshot_as_png
# print(bytes_img)

result=chaojiying.post_pic(bytes_img,'9101')
x,y=result['pic_str'].split(',')
print(x,y)
x=int(x)
y=int(y)
# ActionChains(driver).move_to_element_with_offset(bytes_img,x,y).click().perform()
ActionChains(driver).move_to_element_with_offset(captcha_element, x, y).click().perform()
time.sleep(2)
driver.find_element_by_id('free_login_btn').click()

print(driver.window_handles)
driver.switch_to.window(driver.window_handles[0])
# time.sleep(5)
driver.quit()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Django框架中处理URLconf中特定的URL的方法

有时你有一个模式来处理在你的URLconf中的一系列URL,但是有时候需要特别处理其中的某个URL。 在这种情况下,要使用将URLconf中把特殊情况放在首位的线性处理方式 。 比方说,...

python进阶教程之文本文件的读取和写入

Python具有基本的文本文件读写功能。Python的标准库提供有更丰富的读写功能。 文本文件的读写主要通过open()所构建的文件对象来实现。 创建文件对象 我们打开一个文件,并使用一...

跟老齐学Python之有点简约的元组

关于元组,上一讲中涉及到了这个名词。本讲完整地讲述它。 先看一个例子: >>>#变量引用str >>> s = "abc" >>>...

python字符串替换示例

php5.2升级到5.3后,原& new的写法已经被放弃了,可以直接new了,面对上百个php文件,手动修改简直是想要命,所以写了个脚本,分分钟搞定。 复制代码 代码如下:#-*- co...

Python简单实现阿拉伯数字和罗马数字的互相转换功能示例

Python简单实现阿拉伯数字和罗马数字的互相转换功能示例

本文实例讲述了Python实现阿拉伯数字和罗马数字的互相转换功能。分享给大家供大家参考,具体如下: 前面一篇介绍了《Java实现的求解经典罗马数字和阿拉伯数字相互转换问题》,这里来看看P...