首先,验证码的类型多样,提供一个验证码的破解平台,进行注册,点击下载开发文档
解压后发现有py文件,放到pycharm中
根据chaojiying.py的代码,填写自己的账号和密码和破译验证码的类型
点击后,生成软件id 填写到,py文件中,可以进行实验,实验成功
然后根据这个获取的结果,编写字典,用超级鹰来破解超级鹰的验证码,在编写的代码中有注释
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
import chaojiying
from selenium.webdriver.chrome.options import Options
# 启动 Chrome 浏览器并传入 ChromeOptions
driver = webdriver.Chrome()
# 打开目标网站
driver.get("https://www.chaojiying.com/user/login/")
# 处理验证码
img = driver.find_element(By.XPATH, '/html/body/div[3]/div/div[3]/div[1]/form/div/img').screenshot_as_png
chaojiying = chaojiying.Chaojiying_Client('xxxxxx', 'xxxxxxx.', 'xxxxxx')
dic = chaojiying.PostPic(img, 1902)
code = dic['pic_str']
# 输入用户名
driver.find_element(By.XPATH, '/html/body/div[3]/div/div[3]/div[1]/form/p[1]/input').send_keys("xxxxx")
# 输入密码
driver.find_element(By.XPATH, '/html/body/div[3]/div/div[3]/div[1]/form/p[2]/input').send_keys("xxxxx")
# 输入验证码
driver.find_element(By.XPATH, '/html/body/div[3]/div/div[3]/div[1]/form/p[3]/input').send_keys(code)
# 等待一段时间(可以考虑使用 WebDriverWait 等待特定条件)
time.sleep(5)
# 提交登录
driver.find_element(By.XPATH, '/html/body/div[3]/div/div[3]/div[1]/form/p[4]/input').click()
# 代码执行完成后,由于使用了 "detach" 实验性选项,浏览器窗口不会立即关闭,可以手动进行检查或调试。
运行结束后,窗口会自动关闭,这时添加两行代码,窗口不会自动关闭
# 创建 ChromeOptions 对象
option = webdriver.ChromeOptions()
# 添加实验性选项,使得浏览器窗口在测试完成后不会立即关闭
option.add_experimental_option("detach", True)