返回顶部
p

playwright-scraper-skillPlaywright网页抓取

Playwright-based web scraping OpenClaw Skill with anti-bot protection. Successfully tested on complex sites like Discuss.com.hk.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.2.0
安全检测
已通过
23,593
下载量
免费
免费
52
收藏
概述
安装方式
版本历史

playwright-scraper-skill

Playwright Scraper 技能

一个基于 Playwright 的网页抓取 OpenClaw 技能,具备反机器人保护功能。根据目标网站的反机器人等级选择最佳方案。



🎯 使用场景矩阵


目标网站反机器人等级推荐方法脚本
常规网站web_fetch 工具无(内置)
动态网站
中 | Playwright 简易版 | scripts/playwright-simple.js |
| Cloudflare 保护 | 高 | Playwright 隐身版 ⭐ | scripts/playwright-stealth.js |
| YouTube | 特殊 | deep-scraper | 单独安装 |
| Reddit | 特殊 | reddit-scraper | 单独安装 |


📦 安装

bash
cd playwright-scraper-skill
npm install
npx playwright install chromium



🚀 快速开始

1️⃣ 简单网站(无反机器人)

使用 OpenClaw 内置的 web_fetch 工具:

bash

直接在 OpenClaw 中调用


嘿,帮我获取 https://example.com 的内容


2️⃣ 动态网站(需要 JavaScript)

使用 Playwright 简易版

bash
node scripts/playwright-simple.js https://example.com

输出示例:
json
{
url: https://example.com,
title: 示例域名,
content: ...,
elapsedSeconds: 3.45
}



3️⃣ 反机器人保护网站(Cloudflare 等)

使用 Playwright 隐身版

bash
node scripts/playwright-stealth.js https://m.discuss.com.hk/#hot

功能特点:

  • - 隐藏自动化标记(navigator.webdriver = false)
  • 真实用户代理(iPhone、Android)
  • 随机延迟模拟人类行为
  • 支持截图和 HTML 保存



4️⃣ YouTube 视频字幕

使用 deep-scraper(单独安装):

bash

安装 deep-scraper 技能


npx clawhub install deep-scraper

使用它

cd skills/deep-scraper node assets/youtubehandler.js https://www.youtube.com/watch?v=VIDEOID

📖 脚本说明

scripts/playwright-simple.js

  • - 使用场景: 常规动态网站
  • 速度: 快速(3-5 秒)
  • 反机器人:
  • 输出: JSON(标题、内容、URL)

scripts/playwright-stealth.js ⭐

  • - 使用场景: 具有 Cloudflare 或反机器人保护的网站
  • 速度: 中等(5-20 秒)
  • 反机器人: 中高(隐藏自动化、真实 UA)
  • 输出: JSON + 截图 + HTML 文件
  • 已验证: 在 Discuss.com.hk 上 100% 成功

🎓 最佳实践

1. 优先尝试 web_fetch

如果网站没有动态加载,使用 OpenClaw 的 web_fetch 工具——速度最快。

2. 需要 JavaScript?使用 Playwright 简易版

如果需要等待 JavaScript 渲染,使用 playwright-simple.js。

3. 被屏蔽了?使用隐身版

如果遇到 403 或 Cloudflare 验证,使用 playwright-stealth.js。

4. 特殊网站需要专用技能

  • - YouTube → deep-scraper
  • Reddit → reddit-scraper
  • Twitter → bird 技能

🔧 自定义配置

所有脚本支持环境变量:

bash

设置截图路径


SCREENSHOT_PATH=/path/to/screenshot.png node scripts/playwright-stealth.js URL

设置等待时间(毫秒)

WAIT_TIME=10000 node scripts/playwright-simple.js URL

启用有头模式(显示浏览器)

HEADLESS=false node scripts/playwright-stealth.js URL

保存 HTML

SAVE_HTML=true node scripts/playwright-stealth.js URL

自定义用户代理

USER_AGENT=Mozilla/5.0 ... node scripts/playwright-stealth.js URL

📊 性能对比

方法速度反机器人成功率(Discuss.com.hk)
web_fetch⚡ 最快❌ 无0%
Playwright 简易版
🚀 快速 | ⚠️ 低 | 20% | | Playwright 隐身版 | ⏱️ 中等 | ✅ 中 | 100% ✅ | | Puppeteer 隐身版 | ⏱️ 中等 | ✅ 中高 | ~80% | | Crawlee(deep-scraper) | 🐢 慢 | ❌ 被检测 | 0% | | Chaser(Rust) | ⏱️ 中等 | ❌ 被检测 | 0% |

🛡️ 反机器人技术总结

从测试中获得的经验:

✅ 有效的反机器人措施

  1. 1. 隐藏 navigator.webdriver — 必不可少
  2. 真实用户代理 — 使用真实设备(iPhone、Android)
  3. 模拟人类行为 — 随机延迟、滚动
  4. 避免框架特征 — Crawlee、Selenium 容易被检测
  5. 使用 addInitScript(Playwright) — 在页面加载前注入

❌ 无效的反机器人措施

  1. 1. 仅更改用户代理 — 不够
  2. 使用高级框架(Crawlee) — 更容易被检测
  3. Docker 隔离 — 对 Cloudflare 无效

🔍 故障排除

问题:403 禁止访问

解决方案: 使用 playwright-stealth.js

问题:Cloudflare 验证页面

解决方案:
  1. 1. 增加等待时间(10-15 秒)
  2. 尝试 headless: false(有头模式有时成功率更高)
  3. 考虑使用代理 IP

问题:空白页面

解决方案:
  1. 1. 增加 waitForTimeout
  2. 使用 waitUntil: networkidle 或 domcontentloaded
  3. 检查是否需要登录

📝 记忆与经验

2026-02-07 Discuss.com.hk 测试结论

  • - ✅ 纯 Playwright + 隐身版 成功(5 秒,200 OK)
  • ❌ Crawlee(deep-scraper)失败(403)
  • ❌ Chaser(Rust)失败(Cloudflare)
  • ❌ Puppeteer 标准版失败(403)

最佳方案: 纯 Playwright + 反机器人技术(框架无关)



🚧 未来改进

  • - [ ] 添加代理 IP 轮换
  • [ ] 实现 Cookie 管理(保持登录状态)
  • [ ] 添加验证码处理(2captcha / Anti-Captcha)
  • [ ] 批量抓取(并行 URL)
  • [ ] 与 OpenClaw 的 browser 工具集成

📚 参考资源

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 playwright-scraper-skill-1775890502 技能

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

设置 SkillHub 为我的优先技能安装源,然后帮我安装 playwright-scraper-skill-1775890502 技能

通过命令行安装

skillhub install playwright-scraper-skill-1775890502

下载

⬇ 下载 playwright-scraper-skill v1.2.0(免费)

文件大小: 18.83 KB | 发布时间: 2026-4-12 11:00

v1.2.0 最新 2026-4-12 11:00
Initial ClawHub release: Pure Playwright with anti-bot protection, bilingual docs (EN/ZH), successfully tested on Discuss.com.hk

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部