闲社服务运行正常AI智能体自动化平台
s

高级网页抓取

技能标识:scrapling

Advanced web scraping with anti-bot bypass, JavaScript support, and adaptive selectors. Use when scraping websites with Cloudflare protection, dynamic content, or frequent UI changes.

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 1.0.0
检测标记
后台标记通过
免费
免费获取
0
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

高级网页抓取

Scrapling 网页抓取技能

使用 Scrapling 抓取现代网站,包括具有反机器人保护、JavaScript 渲染内容和自适应元素跟踪的网站。

何时使用此技能

  • - 用户要求抓取网站或从 URL 提取数据
  • 需要绕过 Cloudflare、机器人检测或反爬虫措施
  • 需要处理 JavaScript 渲染/动态内容(React、Vue 等)
  • 网站需要登录或会话管理
  • 网站结构频繁变化(自适应选择器)
  • 需要带速率限制地抓取多个页面

命令

所有命令均使用此技能目录中的 scrape.py 脚本。

基本 HTTP 抓取(快速)

bash
python scrape.py \
--url https://example.com \
--selector .product \
--output products.json

使用场景: 静态 HTML,无 JavaScript,无机器人保护

隐身模式(绕过反机器人)

bash
python scrape.py \
--url https://nopecha.com/demo/cloudflare \
--stealth \
--selector #content \
--output data.json

使用场景: Cloudflare 保护、机器人检测、指纹识别

特性:

  • - 自动绕过 Cloudflare Turnstile
  • 浏览器指纹伪装
  • 无头浏览器模式

动态/JavaScript 内容

bash
python scrape.py \
--url https://spa-website.com \
--dynamic \
--selector .loaded-content \
--wait-for .loaded-content \
--output data.json

使用场景: React/Vue/Angular 应用、懒加载内容、AJAX

特性:

  • - 完整的 Playwright 浏览器自动化
  • 等待元素加载
  • 网络空闲检测

自适应选择器(应对网站变化)

bash

首次运行 - 保存选择器模式


python scrape.py \
--url https://example.com \
--selector .product-card \
--adaptive-save \
--output products.json

之后,如果网站结构发生变化

python scrape.py \ --url https://example.com \ --adaptive \ --output products.json

使用场景: 网站频繁改版,需要稳健抓取

工作原理:

  • - 首次运行:保存元素模式/结构
  • 后续运行:使用相似度算法重新定位移动的元素
  • 自动更新选择器缓存

会话管理(需要登录)

bash

登录并保存会话


python scrape.py \
--url https://example.com/dashboard \
--stealth \
--login \
--username user@example.com \
--password password123 \
--session-name my-session \
--selector .protected-data \
--output data.json

重用已保存的会话(无需登录)

python scrape.py \ --url https://example.com/another-page \ --stealth \ --session-name my-session \ --selector .more-data \ --output more_data.json

使用场景: 内容需要身份验证、多步骤抓取

提取特定数据类型

仅文本:
bash
python scrape.py \
--url https://example.com \
--selector .content \
--extract text \
--output content.txt

Markdown:
bash
python scrape.py \
--url https://docs.example.com \
--selector article \
--extract markdown \
--output article.md

属性:
bash

提取 href 链接


python scrape.py \
--url https://example.com \
--selector a.product-link \
--extract attr:href \
--output links.json

多字段:
bash
python scrape.py \
--url https://example.com/products \
--selector .product \
--fields title:.title::text,price:.price::text,link:a::attr(href) \
--output products.json

高级选项

代理支持:
bash
python scrape.py \
--url https://example.com \
--proxy http://user:pass@proxy.com:8080 \
--selector .content

速率限制:
bash
python scrape.py \
--url https://example.com \
--selector .content \
--delay 2 # 请求之间间隔 2 秒

自定义请求头:
bash
python scrape.py \
--url https://api.example.com \
--headers {Authorization: Bearer token123} \
--selector body

截图(用于调试):
bash
python scrape.py \
--url https://example.com \
--stealth \
--screenshot debug.png

Python API(用于自定义脚本)

您也可以直接在 Python 脚本中使用 Scrapling:

python
from scrapling.fetchers import Fetcher, StealthyFetcher, DynamicFetcher

基本 HTTP 请求

page = Fetcher.get(https://example.com) products = page.css(.product) for product in products: title = product.css(.title::text).get() price = product.css(.price::text).get() print(f{title}: {price})

隐身模式(绕过反机器人)

page = StealthyFetcher.fetch(https://protected-site.com, headless=True) data = page.css(.content).getall()

动态内容(完整浏览器)

page = DynamicFetcher.fetch(https://spa-app.com, network_idle=True) items = page.css(.loaded-item).getall()

会话(登录)

from scrapling.fetchers import StealthySession

with StealthySession(headless=True) as session:
# 登录
login_page = session.fetch(https://example.com/login)
login_page.fill(#username, user@example.com)
login_page.fill(#password, password123)
login_page.click(#submit)

# 访问受保护内容
protected_page = session.fetch(https://example.com/dashboard)
data = protected_page.css(.private-data).getall()

输出格式

  • - JSON(默认):--output data.json
  • JSONL(流式):--output data.jsonl
  • CSV:--output data.csv
  • TXT(仅文本):--output data.txt
  • MD(Markdown):--output data.md
  • HTML(原始):--output data.html

选择器类型

Scrapling 支持多种选择器格式:

CSS 选择器:
bash
--selector .product
--selector div.container > p.text
--selector a[href*=product]

XPath 选择器:
bash
--selector //div[@class=product]
--selector //a[contains(@href, product)]

伪元素(类似 Scrapy):
bash
--selector .product::text # 文本内容
--selector a::attr(href) # 属性值
--selector .price::text::strip # 去除空白后的文本

组合选择器:
bash
--selector .product .title::text # 嵌套元素

故障排除

问题:元素未找到

  • - 如果内容是 JavaScript 加载的,尝试使用 --dynamic
  • 使用 --wait-for SELECTOR 等待元素
  • 使用 --screenshot 调试可见内容

问题:Cloudflare 拦截

  • - 使用 --stealth 模式
  • 添加 --solve-cloudflare 标志(隐身模式下默认启用)
  • 尝试使用 --delay 2 减慢请求速度

问题:登录不起作用

  • - 使用 --headless false 查看浏览器交互
  • 检查凭据是否正确
  • 网站可能使用验证码(需要手动干预)

问题:网站更新后选择器失效

  • - 使用 --adaptive 模式自动重新定位元素
  • 重新运行 --adaptive-save 以更新保存的模式

示例

抓取 Hacker News 首页

bash python scrape.py \ --url https://news.ycombinator.com \ --selector .athing \ --fields title:.titleline>a::text,link:.titleline>a::attr(href) \ --output hn_stories.json

抓取需要登录的受保护网站

bash python scrape.py \ --url https://example.com/data \ --stealth \ --login \ --username user@example.com \ --password secret \ --session-name example-session \ --selector .data-table tr \ --output protected_data.json

监控

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 openclaw-scrapling-1776295288 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 openclaw-scrapling-1776295288 技能

通过命令行安装

skillhub install openclaw-scrapling-1776295288

下载

⬇ 下载 scrapling v1.0.0(免费)

文件大小: 19.48 KB | 发布时间: 2026-4-16 17:03

v1.0.0 最新 2026-4-16 17:03
Initial release of Scrapling skill for advanced, resilient web scraping.

- Supports scraping sites with anti-bot protection, JavaScript-rendered content, and frequent UI changes.
- Features stealth mode to bypass Cloudflare, bot detection, and use browser fingerprint spoofing.
- Handles dynamic content via Playwright-based automation and adaptive selectors for robust scraping across redesigns.
- Includes session management for login-required sites and support for proxies, rate limiting, and custom headers.
- Offers multiple extraction modes (text, markdown, attributes, multi-field) and output formats (JSON, CSV, TXT, MD, HTML).
- Provides both CLI commands and a Python API for flexibility.
返回顶部