验证码滑块识别算法 100% 识别 思路简单(附算法 python 代码)

9 篇文章 1 订阅 ¥299.90 ¥399.90

 

最开始的识别思路是通过模板来找到这个验证码的滑块图像所在的位置,但是使用下来发现准确率在90%左右一起提不上去,无论怎么优化都无法提高,后来发现了一个奇特的思路可用完美解决这个验证码的问题,思路写在了代码里面,最后返回的结果是需要移动的滑块的左上角的坐标点位置(本算法思路主要用在电子税务网站)其他的类似的验证码也可以

识别结果示意图

  • 30
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是一个使用 Selenium 和 Pillow 库识别滑块验证码Python 代码示例: ```python from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from PIL import Image # 初始化浏览器 driver = webdriver.Chrome() driver.get('https://www.example.com') # 找到验证码图片元素和滑块元素 captcha_image = driver.find_element_by_xpath('//*[@id="captcha-image"]') slider_button = driver.find_element_by_xpath('//*[@id="slider-button"]') # 获取验证码图片和滑块位置信息 captcha_location = captcha_image.location slider_location = slider_button.location # 计算滑块相对于验证码图片的偏移量 slider_offset_x = slider_location['x'] - captcha_location['x'] slider_offset_y = slider_location['y'] - captcha_location['y'] # 获取验证码图片 captcha_image_base64 = captcha_image.screenshot_as_base64 captcha_image_data = captcha_image_base64.decode('base64') captcha_image_file = open('captcha.png', 'wb') captcha_image_file.write(captcha_image_data) captcha_image_file.close() # 处理验证码图片,获取有效部分和缺口位置 captcha_image = Image.open('captcha.png') captcha_image = captcha_image.convert('L') captcha_image = captcha_image.crop((0, 0, captcha_image.width - slider_offset_x, captcha_image.height)) captcha_image.save('captcha_cropped.png') captcha_image_data = captcha_image.tobytes() captcha_image_size = captcha_image.size # TODO: 使用机器学习或其他算法识别验证码缺口位置 # 移动滑块完成验证 slider_action = ActionChains(driver) slider_action.click_and_hold(slider_button).perform() slider_action.move_by_offset(captcha_image_size[0] - slider_offset_x, 0).perform() slider_action.release().perform() ``` 需要注意的是,上述代码中的 TODO 部分需要使用机器学习或其他算法识别验证码缺口位置,这是整个验证码识别过程的核心部分,可根据具体情况选择不同的算法和模型进行实现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

点云-激光雷达-Slam-三维牙齿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值