mcpField
S
scrapling

scrapling

github.com/hyperpuncher数据与数据库2274 次安装5 周前更新
代码仓库

关于 scrapling

scrapling 是一项命令行技能,可无需编写代码地抓取网页并提取内容。它针对静态页面、JavaScript 渲染页面和反机器人保护提供不同命令,并可清理供 AI 使用的内容。

主要功能

  1. 01使用 HTTP 方法抓取静态页面
  2. 02抓取 JavaScript 渲染页面
  3. 03抓取有反机器人保护的页面
  4. 04通过 CSS 选择器筛选内容
  5. 05清理供 AI 使用的内容

适用场景

  1. 01将文章内容保存为 Markdown
  2. 02提取匹配的页面元素
  3. 03获取 JavaScript 渲染的内容

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/hyperpuncher/dotagents --skill scrapling

安装后在 Claude Code 中输入/scrapling确认已加载。

详细介绍

scrapling cli

使用 scrapling extract 获取页面并保存所选内容或完整内容,无需编写代码。

设置

uv tool install "scrapling[shell]"
scrapling install

根据版本发布要求更新 Scrapling,并刷新浏览器和指纹:

uv tool upgrade scrapling
scrapling install --force

必要的安全措施

当 AI 模型将读取内容时,务必添加 --ai-targeted。它会保留正文,移除可能包含提示词注入的嘈杂和隐藏内容,剥离注释和零宽字符,并为浏览器命令启用广告拦截。

选择命令

用例命令
静态页面、博客、新闻、APIget、post、put、delete
JavaScript 渲染的页面fetch
Cloudflare 或反机器人防护stealthy-fetch

从 get 开始,然后尝试 fetch,最后尝试 stealthy-fetch。

输出

输出格式由文件扩展名决定:

  • .md:Markdown
  • .html:HTML
  • .txt:纯净文本

建议使用 .md 以提高可读性,并使用 --css-selector 缩减输出内容。

常见示例

# static page
scrapling extract get "https://example.com" /tmp/page.md --ai-targeted

# select matching elements
scrapling extract get "https://example.com" /tmp/articles.md \
	--css-selector "article" --ai-targeted

# query parameters, headers, and cookies
scrapling extract get "https://example.com/search" /tmp/results.md \
	-p "q=scrapling" \
	-H "Accept-Language: en-US" \
	--cookies "session=abc123" \
	--ai-targeted

# form or JSON request
scrapling extract post "https://example.com/search" /tmp/results.txt \
	--data "q=scrapling" --ai-targeted

scrapling extract put "https://example.com/resource" /tmp/result.txt \
	--json '{"enabled":true}' --ai-targeted

# JavaScript-rendered page
scrapling extract fetch "https://example.com" /tmp/page.md \
	--network-idle --ai-targeted

# protected page
scrapling extract stealthy-fetch "https://example.com" /tmp/page.md \
	--solve-cloudflare --ai-targeted

命令完成后读取输出文件,然后清理临时文件。

关键选项

所有命令均支持:

  • -s, --css-selector TEXT:返回所有匹配的元素
  • --ai-targeted:为 AI 消费清理内容
  • --proxy TEXT:代理 URL

HTTP 命令还支持:

  • -H, --headers TEXT:可重复指定的 Key: Value 请求头
  • --cookies TEXT:name=value; name2=value2
  • -p, --params TEXT:可重复指定的查询参数
  • --timeout INTEGER:秒;默认值为 30
  • --impersonate TEXT:浏览器指纹,例如 chrome 或 firefox
  • --follow-redirects / --no-follow-redirects
  • --verify / --no-verify
  • --stealthy-headers / --no-stealthy-headers
  • --data TEXT 和 --json TEXT:适用于 post 和 put

fetch 和 stealthy-fetch 还支持:

  • --headless / --no-headless
  • --network-idle / --no-network-idle
  • --disable-resources / --enable-resources
  • --wait INTEGER:额外等待时间,单位为毫秒
  • --wait-selector TEXT
  • --timeout INTEGER:毫秒;默认值为 30000
  • --locale TEXT
  • -H, --extra-headers TEXT
  • --real-chrome / --no-real-chrome
  • --block-ads / --no-block-ads
  • --dns-over-https / --no-dns-over-https:使用代理时防止 DNS 泄漏
  • --executable-path TEXT:自定义 Chromium 可执行文件;未指定时回退到 SCRAPLING_EXECUTABLE_PATH

stealthy-fetch 还支持:

  • --solve-cloudflare / --no-solve-cloudflare
  • --block-webrtc / --allow-webrtc
  • --allow-webgl / --block-webgl
  • --hide-canvas / --show-canvas

帮助

scrapling extract --help
scrapling extract get --help
scrapling extract fetch --help
scrapling extract stealthy-fetch --help

资源:文档 · github

评论

支持 Markdown