爬虫(滑块验证的破解)

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

复制代码
相关推荐
B站计算机毕业设计之家15 小时前
Python招聘数据分析可视化系统 Boss直聘数据 selenium爬虫 Flask框架 数据清洗(附源码)✅
爬虫·python·selenium·机器学习·数据分析·flask
傻啦嘿哟15 小时前
用Redis实现爬虫URL去重与队列管理:从原理到实战的极简指南
数据库·redis·爬虫
雪碧聊技术15 小时前
爬虫是什么?
大数据·爬虫·python·数据分析
小白学大数据20 小时前
集成Scrapy与异步库:Scrapy+Playwright自动化爬取动态内容
运维·爬虫·scrapy·自动化
深蓝电商API1 天前
异步爬虫的终极形态:aiohttp + asyncio 实现万级并发实践
爬虫·python·aiohttp
电商API_180079052471 天前
从客户需求到 API 落地:淘宝商品详情批量爬取与接口封装实践
大数据·人工智能·爬虫·数据挖掘
深蓝电商API1 天前
爬虫性能压榨艺术:深入剖析 Scrapy 内核与中间件优化
爬虫·scrapy
傻啦嘿哟1 天前
爬虫数据去重:BloomFilter算法实现指南
爬虫·算法
Jonathan Star2 天前
网站识别爬虫(包括以浏览器插件形式运行的爬虫)主要通过分析请求特征、行为模式等差异来区分人类用户和自动化程序
运维·爬虫·自动化
深蓝电商API3 天前
从爬虫到平台:如何把你的爬虫项目做成一个技术产品?
爬虫·信息可视化·数据挖掘