【原创】Python 极验滑块验证

简介: 【原创】Python 极验滑块验证



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

记一次 极验滑块验证分析并通过

操作环境

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

分析

最近在做的一个项目登录时会触发一个滑块验证,就长下面这个样子可以很明显的看出来是极验3代验证,借助之前写阿里云盾的经验使用selenium+pyautoui先测试一下,详细可参考:阿里云盾滑块验证直接提示被怪物吃掉了!!!还是先来研究一下官方文档看一下验证的业务逻辑:极验验证接入文档本以为是检测到了selenium,手动测试了一下发现是可以滑过的,那就是说明应该是滑动的轨迹触发了风控。

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

解决方案

使用selenium请求url,并触发滑块验证

defopen(self):

  """

   登录模块

   """

   # 定位密码登录

   self.driver.find_element_by_xpath('//*[@id="app"]/div/div/div/div/div/div[1]/div[2]').click()

   # 输入账号

   username = '123456'

   self.driver.find_element_by_xpath('//*[@id="app"]/div/div/div/div/div/div[2]/div[1]/form/div[1]/div/div/input').send_keys(username)

   time.sleep(1)

   # 输入密码

   password = '123456789'

   self.driver.find_element_by_xpath('//*[@id="app"]/div/div/div/div/div/div[2]/div[1]/form/div[2]/div/div/input').send_keys(password)

   time.sleep(1)

   # 登录

   self.driver.find_element_by_xpath('//*[@id="app"]/div/div/div/div/div/div[2]/div[3]/button').click()

获取验证图片并计算滑块距离

defget_images(self):

  """

  获取验证码图片

  :return: 图片的location信息

  """

  # 带缺口图片,使用js定位并读取图片的data信息 data:image/png;base64,直接调用识别缺口

  fullgb = self.driver.execute_script('return document.getElementsByClassName("geetest_canvas_bg geetest_absolute")[0].toDataURL("image/png")')

  # 完整图片,使用js定位并读取图片的data信息 data:image/png;base64,直接调用识别缺口

  bg = self.driver.execute_script('return document.getElementsByClassName("geetest_canvas_fullbg geetest_fade geetest_absolute")[0].toDataURL("image/png")')

  returnbg, fullgb

defget_decode_image(self, location_list):

  """

  解码图片的base64数据

  """

  # 提取图片base64数据

  _, img = location_list.split(",")

  # 数据转换为Bytes字节

  img = base64.decodebytes(img.encode())

  # 读取图片

  new_im: PngImagePlugin.PngImageFile = image.open(BytesIO(img))

  # new_im.convert("RGB")

  # new_im.save(filename)

  returnnew_im

defcompute_gap(self, img1, img2):

  """

  计算缺口偏移 这种方式成功率很高

  """

  # 将图片修改为RGB模式

  img1 = img1.convert("RGB")

  img2 = img2.convert("RGB")

  # 计算差值

  diff = ImageChops.difference(img1, img2)

  # 灰度图

  diff = diff.convert("L")

  # 二值化

  diff = diff.point(self.table, '1')

  left = 43

  forwinrange(left, diff.size[0]):

      lis = []

      forhinrange(diff.size[1]):

          ifdiff.load()[w, h] == 1:

              lis.append(w)

          iflen(lis) >5:

              returnw

生成滑动轨迹

defget_tracks(self, distance, seconds, ease_func):

   """

   :param distance: 缺口位置

   :param seconds:  时间

   :param ease_func: 生成函数

   :return: 轨迹数组

   """

   tracks = [0]

   offsets = [0]

   fortinnp.arange(0.0, seconds, 0.1):

       ease = ease_func

       offset = round(ease(t/seconds) *distance)

       tracks.append(offset-offsets[-1])

       offsets.append(offset)

   returntracks

滑动模块

defmove_to_gap(self, track):

    """滑动滑块"""

    print('第一步,点击滑动按钮')

    slider = self.wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'geetest_slider_button')))

    ActionChains(self.driver).click_and_hold(slider).perform()

    time.sleep(1)

    print('第二步,拖动元素')

    fortrackintrack:

        ActionChains(self.driver).move_by_offset(xoffset=track, yoffset=0).perform()  # 鼠标移动到距离当前位置(x,y)

        time.sleep(0.0001)

效果

完美解决


资源下载

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


本文仅供学习交流使用,如侵立删!
目录
打赏
0
0
0
0
157
分享
相关文章
2025python实战:利用海外代理IP验证广告投放效果
本文介绍了如何利用Python结合海外代理IP技术,验证广告在不同国家的实际投放效果。通过模拟各地网络环境访问广告页面,检查内容是否与计划一致,并生成曝光报告。具体实现包括:获取高质量代理IP、使用Selenium或Playwright模拟用户行为、解析广告内容及生成可视化报告。案例显示,该方法能有效确保广告精准投放,优化策略并节省预算。
Python编程:利用JSON模块编程验证用户
Python编程:利用JSON模块编程验证用户
75 1
HTTPS 请求中的证书验证详解(Python版)
HTTPS 请求中的证书验证详解(Python版)
524 0
|
11月前
|
【Leetcode刷题Python】946. 验证栈序列
LeetCode题目“946. 验证栈序列”的Python解决方案,通过模拟栈的压入和弹出操作来验证给定的两个序列是否能通过合法的栈操作得到。
94 6
【经典算法】LeetCode 125. 验证回文串(Java/C/Python3实现含注释说明,Easy)
【经典算法】LeetCode 125. 验证回文串(Java/C/Python3实现含注释说明,Easy)
94 0

推荐镜像

更多
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等