爬虫(滑块验证的破解)

基于滑块的验证破解 ------ Selenium

1.可分为三个核心步骤
  • 获取验证码图片
  • 识别图片,计算轨迹距离
  • 寻找滑块,控制滑动

打开网址:https://www.geetest.com/adaptive-captcha-demo

2.获取验证图片
python 复制代码
import re
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

service = Service('driver/chromedriver.exe')
driver = webdriver.Chrome(service=service)

# 1.打开首页
driver.get('https://www.geetest.com/adaptive-captcha-demo')

# 2.点击【滑动图片验证】
tag = WebDriverWait(driver, 30, 0.5).until(lambda dv: dv.find_element(
    By.XPATH,
    '//*[@id="gt-showZh-mobile"]/div/section/div/div[2]/div[1]/div[2]/div[3]/div[3]',
))
tag.click()

# 3.点击开始验证
tag = WebDriverWait(driver, 30, 0.5).until(lambda dv: dv.find_element(
    By.CLASS_NAME,
    'geetest_btn_click',
))
tag.click()

# 4.获取背景图片 - 使用了闭包
def fetch_image_func(class_name):
    def inner(dv):
        tag_object = dv.find_element(
            By.CLASS_NAME,
            class_name,
        )

        style_string = tag_object.get_attribute('style')
        match_list = re.findall('url\(\"(.*)\"\);', style_string)
        if match_list:
            return match_list[0]
        return
    return inner

bg_img_url = WebDriverWait(driver, 30, 0.5).until(fetch_image_func('geetest_bg'))
print(f'背景图:{bg_img_url}')


slice_image_url = WebDriverWait(driver, 30, 0.5).until(fetch_image_func('geetest_slice_bg'))
print(f'背景图:{slice_image_url}')

time.sleep(2)
driver.close()

t(f'背景图:{slice_image_url}')

time.sleep(2)

driver.close()

复制代码
相关推荐
华科云商xiao徐4 小时前
告别IP被封!分布式爬虫的“隐身”与“分身”术
爬虫·数据挖掘·数据分析
q567315238 小时前
告别低效:构建健壮R爬虫的工程思维
开发语言·爬虫·r语言
一个天蝎座 白勺 程序猿17 小时前
Python爬虫(47)Python异步爬虫与K8S弹性伸缩:构建百万级并发数据采集引擎
爬虫·python·kubernetes
华科云商xiao徐1 天前
告别低效:构建健壮R爬虫的工程思维
爬虫
熊猫钓鱼>_>2 天前
2025反爬虫之战札记:从robots.txt到多层防御的攻防进化史
开发语言·c++·爬虫
Blurpath2 天前
如何利用静态代理IP优化爬虫策略?从基础到实战的完整指南
爬虫·网络协议·ip代理·住宅代理
wjayg2252 天前
网络爬虫是自动从互联网上采集数据的程序
爬虫
IT毕设实战小研2 天前
2026届大数据毕业设计选题推荐-基于大数据旅游数据分析与推荐系统 爬虫数据可视化分析
大数据·人工智能·爬虫·机器学习·架构·数据分析·课程设计
Villiam_AY2 天前
使用 chromedp 高效爬取 Bing 搜索结果
后端·爬虫·golang
爬虫程序猿3 天前
利用 Java 爬虫获取淘宝商品 SKU 详细信息实战指南
java·开发语言·爬虫