Python 阿里云盾滑块验证



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


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

操作环境

  • win10 、 mac
  • Python3.9
  • selenium、pyautogui

分析

最近在做中国庭审公开网数据分析的时候发现每次打开一个新的页面都会触发滑块验证,就长下面这个样子Python 阿里云盾滑块验证_第1张图片

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

Python 阿里云盾滑块验证_第2张图片


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

1

2

3

# 最新版本谷歌浏览器 绕过检测

chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])

chrome_options.add_argument('--disable-blink-features=AutomationControlled')

后陆续尝试过,降低chrome版本,修改chromedriver驱动文件,均不成功。
现在看来是真的有点东西!!!正在一筹莫展时,直到看到了这个

Python 阿里云盾滑块验证_第3张图片 

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

Python 阿里云盾滑块验证_第4张图片 

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

解决方案

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

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, 101)  # 设置隐式等待时间

    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(1086340, duration=1)

    # 按方向拖动

    # 向右拖动100px,向下拖动500px, 这个过程持续 1 秒钟

    pyautogui.dragRel(2600, duration=0.5)  # 第一个参数是左右移动像素值,第二个是上下

效果


完美解决


 

你可能感兴趣的:(逆向开发,python,macos,开发语言)