当前位置 : 主页 > 编程语言 > python >

Python 阿里云盾滑块验证

来源:互联网 收集:自由互联 发布时间:2022-06-15
tabletrtd bgcolor=orange本文仅供学习交流使用,如侵立删!/td/tr/table 记一次阿里云盾滑块验证分析并通过 操作环境 win10 、 mac Python3.9 selenium、pyautogui 分析 最近在做中国庭审公开网数据分

<table><tr><td bgcolor=orange>本文仅供学习交流使用,如侵立删!</td></tr></table>


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

操作环境

  • 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) # 第一个参数是左右移动像素值,第二个是上下

效果

请添加图片描述完美解决



<table><tr><td bgcolor=orange>本文仅供学习交流使用,如侵立删!</td></tr></table>


网友评论