Python 阿里云盾滑块验证

2022-10-15,,,

本文仅供学习交流使用,如侵立删!

记一次阿里云盾滑块验证分析并通过

操作环境

win10 、 mac
Python3.9
selenium、pyautogui

分析

最近在做中国庭审公开网数据分析的时候发现每次打开一个新的页面都会触发滑块验证,就长下面这个样子

本以为使用selenium定位到滑块元素拖动即可,满心欢喜开始写代码,测试后发现还是高兴太早了~~~

貌似有点东西,原以为是因为检测到了selenium的原因,添加防检测代码

# 最新版本谷歌浏览器 绕过检测
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
chrome_options.add_argument('--disable-blink-features=AutomationControlled')

后陆续尝试过,降低chrome版本,修改chromedriver驱动文件,均不成功。

现在看来是真的有点东西!!!正在一筹莫展时,直到看到了这个

经过分析网页源码发现原来是使用了阿里云盾的人机效验,详细介绍请参考官方产品文档:阿里云验证码产品文档

分析了一波效验规则及原理,搞明白原理就好办了

解决方案

1.使用selenium请求url,并触发滑块验证
2.使用pyautogui操控鼠标滑动

    def __init__(self):
chrome_options = Options()
# 最新版本谷歌浏览器 绕过检测
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
chrome_options.add_argument('--disable-blink-features=AutomationControlled')
self.driver = webdriver.Chrome('./config/chromedriver.exe', options=chrome_options)
self.wait = WebDriverWait(self.driver, 10, 1) # 设置隐式等待时间
self.driver.maximize_window() def run(self):
"""程序入口"""
print(f'打开首页:http://tingshen.court.gov.cn/preview')
self.driver.get('http://tingshen.court.gov.cn/preview') # 拖动到指定位置
# 将鼠标拖动到指定的坐标;duration 的作用是设置移动时间,所有的gui函数都有这个参数,而且都是可选参数
pyautogui.dragTo(1086, 340, duration=1) # 按方向拖动
# 向右拖动100px,向下拖动500px, 这个过程持续 1 秒钟
pyautogui.dragRel(260, 0, duration=0.5) # 第一个参数是左右移动像素值,第二个是上下

效果

完美解决


资源下载

https://download.csdn.net/download/qq_38154948/85204671


本文仅供学习交流使用,如侵立删!

Python 阿里云盾滑块验证的相关教程结束。

《Python 阿里云盾滑块验证.doc》

下载本文的Word格式文档,以方便收藏与打印。