📦 OpenClaw Scrapling — 反爬虫抓取

v1.0.0

基于 Playwright 的浏览器级抓取工具,自动绕过 Cloudflare、JS 挑战与指纹检测,支持动态渲染、代理、登录会话、自适应选择器与多格式输出,可应对站点改版。

0· 909·7 当前·7 累计
cryptos3c 头像by @cryptos3c·MIT-0
下载技能包
License
MIT-0
最后更新
2026/4/11
0
安全扫描
VirusTotal
可疑
查看报告
OpenClaw
安全
high confidence
该技能的文件、依赖和运行指令与使用 Playwright 风格浏览器及自适应选择器缓存的网页抓取工具一致;包内未发现除抓取外的可疑行为。
评估建议
该包作为高级网页抓取器内部逻辑一致——将运行 Python 代码、下载浏览器二进制文件并可访问任意 URL(含内网地址)。安装前请注意: - 仅在你信任源码(GitHub 仓库)并接受本技能会运行代码及下载约 500MB 浏览器二进制的前提下安装。 - 会话 Cookie 与选择器缓存将写入技能目录(~/.openclaw/skills/scrapling/sessions 与 selector_cache.json);若含敏感令牌请及时删除。 - 除非信任本工具及运行环境,切勿向其传递机密或站点凭据;CLI 参数中的用户名/密码仅在保存会话时才会落盘。 - 若担心数据外泄或内网访问,请在受限环境(网络策略、sandbox 或 VM)中运行,并在使用前检查 scrape.py 及已安装的 scrapling 包源码。 - 如需最小权限,避免启用会启动浏览器或保存会话的 stealth/dynamic 模式,优先使用一次性的安全 HTTP 抓取并显式指定安全目标 URL。...
详细分析 ▾
用途与能力
名称/描述与代码和文档一致:scrape.py、示例、requirements.txt 和 skill.json 均实现了具备隐身/动态/自适应功能的抓取器。声明的必需二进制文件(python3、pip)及 Python 包依赖(scrapling)均符合所述功能。元数据中的次要版本差异(>=0.3.0 vs >=0.4.0)本身并非危险信号。
指令范围
SKILL.md 和 scrape.py 指示智能体运行本地抓取命令,并将会话/选择器存储在技能目录。指令允许抓取任意 URL(外部或内部)、执行登录(通过 CLI 参数传递用户名/密码)、保存会话文件、截图并写入输出。它们未指示读取无关系统文件或环境变量,但允许通过 CLI 参数发送凭据并将会话令牌/Cookie 持久化到磁盘。
安装机制
注册表条目内无内置安装规范,但仓库包含 requirements.txt 及文档化的安装步骤,会调用 'pip install -r requirements.txt' 和 'scrapling install',从而下载浏览器二进制文件(约 500MB)。这对基于浏览器的抓取器属预期行为;包本身未使用可疑的外部下载 URL 或短链。浏览器下载将在运行时执行辅助命令时发生。
凭证需求
该技能未声明需要环境变量或凭据,符合其描述目的。然而,工具通过 CLI 参数接受凭据(用户名/密码)并会在技能目录中持久化会话状态(会话文件和 selector_cache.json)。这些行为对抓取器合理,但意味着若提供凭据,技能可存储敏感令牌/凭据。
持久化与权限
always:false(无强制安装)。技能将文件写入自身目录(sessions/、selector_cache.json)并在执行 'scrapling install' 时将浏览器下载到标准缓存。这对该类工具属正常行为,但意味着数据与 Cookie 将在磁盘上的技能及浏览器缓存目录中持续存在,除非手动清理。
安全有层次,运行前请审查代码。

License

MIT-0

可自由使用、修改和再分发,无需署名。

运行时依赖

无特殊依赖

版本

latestv1.0.02026/2/27

Scrapling 技能初始发布,用于高级、弹性网页抓取。 - 支持抓取带反机器人保护、JavaScript 渲染内容及频繁 UI 变更的站点。 - 隐身模式可绕过 Cloudflare、机器人检测并使用浏览器指纹欺骗。 - 通过基于 Playwright 的自动化处理动态内容,自适应选择器在站点改版时仍保持稳健抓取。 - 包含登录站点的会话管理,支持代理、速率限制及自定义请求头。 - 提供多种提取模式(文本、markdown、属性、多字段)及输出格式(JSON、CSV、TXT、MD、HTML)。 - 同时提供 CLI 命令与 Python API,灵活易用。

可疑

安装命令

点击复制
官方npx clawhub@latest install openclaw-scrapling
镜像加速npx clawhub@latest install openclaw-scrapling --registry https://cn.longxiaskill.com

技能文档

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

何时使用此技能

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

命令

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

基础 HTTP 抓取(快速)

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

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

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

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

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

功能特点:

  • 自动绕过 Cloudflare Turnstile
  • 浏览器指纹欺骗
  • 无头浏览器模式

动态/JavaScript 内容

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

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

功能特点:

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

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

# 首次运行 - 保存选择器模式
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

适用场景: 网站频繁改版、需要健壮的抓取

工作原理:

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

会话管理(需要登录)

# 登录并保存会话
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

适用场景: 内容需要认证、多步骤抓取

提取特定数据类型

仅文本:

python scrape.py \
  --url "https://example.com" \
  --selector ".content" \
  --extract text \
  --output content.txt

Markdown:

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

属性:

# 提取 href 链接
python scrape.py \
  --url "https://example.com" \
  --selector "a.product-link" \
  --extract attr:href \
  --output links.json

多个字段:

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

高级选项

代理支持:

python scrape.py \
  --url "https://example.com" \
  --proxy "http://user:pass@proxy.com:8080" \
  --selector ".content"

速率限制:

python scrape.py \
  --url "https://example.com" \
  --selector ".content" \
  --delay 2 # 请求之间等待 2 秒

自定义请求头:

python scrape.py \
  --url "https://api.example.com" \
  --headers '{"Authorization": "Bearer token123"}' \
  --selector "body"

截图(用于调试):

python scrape.py \
  --url "https://example.com" \
  --stealth \
  --screenshot debug.png

Python API(用于自定义脚本)

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

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 选择器:

--selector ".product"
--selector "div.container > p.text"
--selector "a[href*='product']"

XPath 选择器:

--selector "//div[@class='product']"
--selector "//a[contains(@href, 'product')]"

伪元素(类似 Scrapy):

--selector ".product::text"           # 文本内容
--selector "a::attr(href)"            # 属性值
--selector ".price::text::strip"      # 去除空白的文本

组合选择器:

--selector ".product .title::text"    # 嵌套元素

故障排除

问题:"Element not found"(未找到元素)

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

问题:"Cloudflare blocking"(Cloudflare 阻止)

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

问题:"Login not working"(登录不工作)

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

问题:"Selector broke after website update"(网站更新后选择器失效)

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

示例

抓取 Hacker News 首页

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

使用登录抓取受保护网站

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

监控价格变化

# 保存初始选择器模式
python scrape.py \
  --url "https://store.com/product/123" \
  --selector ".price" \
  --adaptive-save \
  --output price.txt

# 之后检查价格(即使页面已改版) python scrape.py \ --url "https://store.com/product/123" \ --adaptive \ --output price_new.txt

抓取动态 JavaScript 应用

python scrape.py \
  --url "https://react-app.com/data" \
  --dynamic \
  --wait-for ".loaded-content" \
  --selector ".item" \
  --fields "name:.name::text,value:.value::text" \
  --output app_data.json

注意事项

  • 首次运行:Scrapling 会下载浏览器(约 500MB)。这是自动完成的。
  • 会话:保存在 sessions/ 目录中,可跨运行重用
  • 自适应缓存:保存在 selector_cache.json 中,自动更新
  • 速率限制:始终尊重 robots.txt 并添加延迟以进行道德抓取
  • 法律:仅在您有权限抓取的网站上使用

依赖项

安装技能时自动安装:

  • scrapling[all] - 包含所有功能的主库
  • pyyaml - 用于配置文件支持

技能结构

scrapling/
├── SKILL.md               # 本文件
├── scrape.py              # 主 CLI 脚本
├── requirements.txt       # Python 依赖
├── sessions/              # 保存的浏览器会话
├── selector_cache.json    # 自适应选择器模式
└── examples/              # 示例脚本
    ├── basic.py
    ├── stealth.py
    ├── dynamic.py
    └── adaptive.py

高级:自定义 Python 脚本

对于复杂的爬取任务,你可以在此目录中创建自定义 Python 脚本:

# custom_scraper.py
from scrapling.fetchers import StealthyFetcher
from scrapling.spiders import Spider, Response
import json

class MySpider(Spider): name = "custom" start_urls = ["https://example.com/page1"]

async def parse(self, response: Response): for item in response.css('.product'): yield { "title": item.css('.title::text').get(), "price": item.css('.price::text').get() }

# Follow pagination next_page = response.css('.next-page::attr(href)').get() if next_page: yield response.follow(next_page)

# Run spider result = MySpider().start()

with open('output.json', 'w') as f: json.dump(result.items, f, indent=2)

运行方式:

python custom_scraper.py

有疑问?

查看 Scrapling 文档:https://scrapling.readthedocs.io

数据来源ClawHub ↗ · 中文优化:龙虾技能库