爬虫(滑块验证的破解)

基于滑块的验证破解 ------ 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()

复制代码
相关推荐
小小码农一只2 小时前
Python 爬虫实战:玩转 Playwright 跨浏览器自动化(Chromium/Firefox/WebKit 全支持)
爬虫·python·自动化
weixin_443353311 天前
小红书帖子评论的nodejs爬虫脚本
前端·爬虫
TLuoQiu2 天前
小电视视频内容获取GUI工具
爬虫·python
麦麦大数据2 天前
F004 新闻可视化系统爬虫更新数据+ flask + mysql架构
爬虫·mysql·flask·可视化·新闻
python-行者2 天前
akamai鼠标轨迹
爬虫·python·计算机外设·akamai
NEUMaple3 天前
python爬虫(四)----requests
开发语言·爬虫·python
电商API_180079052473 天前
大规模调用淘宝商品详情 API 的分布式请求调度实践
服务器·数据库·分布式·爬虫
小白学大数据3 天前
1688商品数据抓取:Python爬虫+动态页面解析
爬虫·python·okhttp
forestsea3 天前
Nginx蜘蛛请求智能分流:精准识别爬虫并转发SEO渲染服务
运维·爬虫·nginx
华科云商xiao徐3 天前
突破Python性能墙:关键模块C++化的爬虫优化指南
c++·爬虫·python