目录

爬虫(滑块验证的破解)

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

复制代码
本文是转载文章,点击查看原文
如有侵权,请联系 xyy@jishuzhan.net 删除
相关推荐
十分钟空间15 小时前
别再手动查热点了!200行Python代码搞定微博知乎头条等全网焦点,小白也能快速上手
爬虫·ai编程
davenian20 小时前
< 自用文 Project-30.6 Crawl4AI > 为AI模型优化的网络爬虫工具 帮助收集和处理网络数据的工具
爬虫·crawl4ai
ONE_Gua2 天前
魔改chromium源码——canvas指纹修改 第二节
chrome·爬虫·浏览器
攻城狮7号2 天前
Python爬虫第13节-解析库pyquery 的使用
爬虫·python·python爬虫
Blood_J2 天前
python网络爬虫
开发语言·爬虫·python
q567315232 天前
使用Java的HttpClient实现文件下载器
java·开发语言·爬虫·scrapy
MinggeQingchun2 天前
Python - 爬虫-网页抓取数据-库requests
爬虫·python·requests
q567315232 天前
使用libcurl编写爬虫程序指南
开发语言·c++·爬虫
sa100272 天前
基于Python的网络爬虫技术研究
开发语言·爬虫·python
API小爬虫2 天前
如何利用 Java 爬虫获取京东商品详情信息
java·开发语言·爬虫