前言:
【文章末尾给大家留下了大量的福利哈】
就是图中的这种滑块验证码

先贴源码,基本思路就是 用PIL,然后对比 验证码图片 有缺口和无缺口的不同,计算出偏移量,模拟滑块滑动。
import random
import io
from PIL import Image
from urllib.request import urlopen
from selenium.webdriver.common.action_chains import ActionChains
import time
# 打开图片链接
def open_img_url(src):
img_url = urlopen(src, timeout=2).read()
img = Image.open(io.BytesIO(img_url))
# 恢复原始大小
img_resize = (int(i // 2) for i in img.size)
return img.resize(img_resize, Image.ANTIALIAS)
def get_img(dr):
dr.switch_to.frame('tcaptcha_iframe')
src1 = dr.find_element_by_id('slideBg').get_attribute('src')
src2 = src1.replace('img_index=1', 'img_index=0')
return open_img_url(src1), open_img_url(src2)
# 比较两张图片同一点上的像数值,差距大于设置标准返回False
def is_pi

这篇博客介绍了一种使用Python和Selenium库自动化处理滑块验证码的方法。通过比较有缺口和无缺口的验证码图片,计算偏移量并模拟滑动轨迹,最终实现自动拖动滑块验证。代码详细展示了如何打开图片、获取偏移量、模拟滑动轨迹以及释放鼠标等步骤,为自动化测试提供了便利。
最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



