🕸️

Playwright 驱动·智能反爬网页采集

Playwright Scraper Skill · v1.2.0
入口已确认,内容待校验 文件树里有 SKILL.md,但正文还没采回,frontmatter 未核对。
专业技能 安全 A 级 作者 waisimon 公开目录收录
25.8k 下载 54 安装 95.4k 收藏 332 浏览

简介

基于 Playwright 的网页爬虫 Skill,支持动态渲染和反爬隐身模式,已验证可绕过 Cloudflare 防护,适合采集复杂动态站点数据。

原始描述

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

通过你的 Agent 添加

安装目录:playwright-scraper-skill/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/playwright-scraper-skill/
Codex CLI~/.codex/skills/playwright-scraper-skill/
DeepSeek Harness~/.agents/skills/playwright-scraper-skill/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

中文使用说明 来自收录源

核心用法

Playwright Scraper Skill 是一套分层网页抓取解决方案,提供三种爬取策略:

  1. 内置 web_fetch — 适用于静态网站,速度最快
  2. Playwright Simple — 适用于JavaScript动态渲染网站
  3. Playwright Stealth ⭐ — 适用于Cloudflare等反爬保护网站

使用时根据目标网站反爬等级选择对应脚本,通过命令行直接调用,支持环境变量自定义截图路径、等待时间、User-Agent等参数。

显著优点

  • 实战验证的反爬能力:在Discuss.com.hk测试中,Stealth模式实现100%成功率,而Crawlee、Puppeteer标准模式均失败
  • 技术方案纯粹:不依赖Crawlee等高层框架,直接使用Playwright底层API,降低被检测风险
  • 灵活可配置:支持headful/headless模式切换、自定义等待策略、截图/HTML保存
  • 依赖安全可靠:仅依赖Microsoft官方Playwright库,无供应链风险
  • 分层架构合理:从简单到复杂场景都有对应方案,避免过度使用重型工具

潜在缺点与局限性

  • 反爬伦理灰色地带:隐藏navigator.webdriver、模拟真实设备指纹等技术虽合法,但可能违反目标网站服务条款
  • 无内置代理轮换:高频率爬取同一站点时IP易被封锁,需手动配置代理
  • 无验证码处理:遇到CAPTCHA时需借助第三方服务(2captcha等),暂未集成
  • 无登录状态保持:缺乏cookie管理和会话持久化功能
  • 容器环境限制:默认使用--no-sandbox参数,存在潜在安全风险

适合人群

  • 数据分析师、研究人员需要抓取受保护公开数据
  • 开发者构建竞品监控、价格追踪等自动化工具
  • 已有一定Node.js基础,能根据目标站点特性调整参数

常规风险

  • 法律合规风险:需遵守robots.txt及目标网站ToS,某些司法管辖区对爬虫有专门立法
  • IP封禁风险:即使Stealth模式成功,高频请求仍可能触发速率限制
  • 数据隐私风险:抓取内容可能含个人信息,需符合GDPR/CCPA等法规
  • 技术对抗升级:反爬与反反爬是持续军备竞赛,当前有效技术可能随对方升级失效

技能正文


name: playwright-scraper-skill description: Playwright-based web scraping OpenClaw Skill with anti-bot protection. Successfully tested on complex sites like Discuss.com.hk. version: 1.2.0 author: Simon Chan

Playwright Scraper Skill

A Playwright-based web scraping OpenClaw Skill with anti-bot protection. Choose the best approach based on the target website's anti-bot level.


🎯 Use Case Matrix

Target Website Anti-Bot Level Recommended Method Script
Regular Sites Low web_fetch tool N/A (built-in)
Dynamic Sites Medium Playwright Simple scripts/playwright-simple.js
Cloudflare Protected High Playwright Stealth ⭐ scripts/playwright-stealth.js
YouTube Special deep-scraper Install separately
Reddit Special reddit-scraper Install separately

📦 Installation

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

🚀 Quick Start

1️⃣ Simple Sites (No Anti-Bot)

Use OpenClaw's built-in web_fetch tool:

# Invoke directly in OpenClaw
Hey, fetch me the content from https://example.com

2️⃣ Dynamic Sites (Requires JavaScript)

Use Playwright Simple:

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

Example output:

{
  "url": "https://example.com",
  "title": "Example Domain",
  "content": "...",
  "elapsedSeconds": "3.45"
}

3️⃣ Anti-Bot Protected Sites (Cloudflare etc.)

Use Playwright Stealth:

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

Features:

  • Hide automation markers (navigator.webdriver = false)
  • Realistic User-Agent (iPhone, Android)
  • Random delays to mimic human behavior
  • Screenshot and HTML saving support

4️⃣ YouTube Video Transcripts

Use deep-scraper (install separately):

# Install deep-scraper skill
npx clawhub install deep-scraper

# Use it
cd skills/deep-scraper
node assets/youtube_handler.js "https://www.youtube.com/watch?v=VIDEO_ID"

📖 Script Descriptions

scripts/playwright-simple.js

  • Use Case: Regular dynamic websites
  • Speed: Fast (3-5 seconds)
  • Anti-Bot: None
  • Output: JSON (title, content, URL)

scripts/playwright-stealth.js ⭐

  • Use Case: Sites with Cloudflare or anti-bot protection
  • Speed: Medium (5-20 seconds)
  • Anti-Bot: Medium-High (hides automation, realistic UA)
  • Output: JSON + Screenshot + HTML file
  • Verified: 100% success on Discuss.com.hk

🎓 Best Practices

1. Try web_fetch First

If the site doesn't have dynamic loading, use OpenClaw's web_fetch tool—it's fastest.

2. Need JavaScript? Use Playwright Simple

If you need to wait for JavaScript rendering, use playwright-simple.js.

3. Getting Blocked? Use Stealth

If you encounter 403 or Cloudflare challenges, use playwright-stealth.js.

4. Special Sites Need Specialized Skills

  • YouTube → deep-scraper
  • Reddit → reddit-scraper
  • Twitter → bird skill

🔧 Customization

All scripts support environment variables:

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

# Set wait time (milliseconds)
WAIT_TIME=10000 node scripts/playwright-simple.js URL

# Enable headful mode (show browser)
HEADLESS=false node scripts/playwright-stealth.js URL

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

# Custom User-Agent
USER_AGENT="Mozilla/5.0 ..." node scripts/playwright-stealth.js URL

📊 Performance Comparison

Method Speed Anti-Bot Success Rate (Discuss.com.hk)
web_fetch ⚡ Fastest ❌ None 0%
Playwright Simple 🚀 Fast ⚠️ Low 20%
Playwright Stealth ⏱️ Medium ✅ Medium 100% ✅
Puppeteer Stealth ⏱️ Medium ✅ Medium-High ~80%
Crawlee (deep-scraper) 🐢 Slow ❌ Detected 0%
Chaser (Rust) ⏱️ Medium ❌ Detected 0%

🛡️ Anti-Bot Techniques Summary

Lessons learned from our testing:

✅ Effective Anti-Bot Measures

  1. Hide navigator.webdriver — Essential
  2. Realistic User-Agent — Use real devices (iPhone, Android)
  3. Mimic Human Behavior — Random delays, scrolling
  4. Avoid Framework Signatures — Crawlee, Selenium are easily detected
  5. Use addInitScript (Playwright) — Inject before page load

❌ Ineffective Anti-Bot Measures

  1. Only changing User-Agent — Not enough
  2. Using high-level frameworks (Crawlee) — More easily detected
  3. Docker isolation — Doesn't help with Cloudflare

🔍 Troubleshooting

Issue: 403 Forbidden

Solution: Use playwright-stealth.js

Issue: Cloudflare Challenge Page

Solution:

  1. Increase wait time (10-15 seconds)
  2. Try headless: false (headful mode sometimes has higher success rate)
  3. Consider using proxy IPs

Issue: Blank Page

Solution:

  1. Increase waitForTimeout
  2. Use waitUntil: 'networkidle' or 'domcontentloaded'
  3. Check if login is required

📝 Memory & Experience

2026-02-07 Discuss.com.hk Test Conclusions

  • ✅ Pure Playwright + Stealth succeeded (5s, 200 OK)
  • ❌ Crawlee (deep-scraper) failed (403)
  • ❌ Chaser (Rust) failed (Cloudflare)
  • ❌ Puppeteer standard failed (403)

Best Solution: Pure Playwright + anti-bot techniques (framework-independent)


🚧 Future Improvements

  • Add proxy IP rotation
  • Implement cookie management (maintain login state)
  • Add CAPTCHA handling (2captcha / Anti-Captcha)
  • Batch scraping (parallel URLs)
  • Integration with OpenClaw's browser tool

📚 References

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

web-scrapingplaywrightbrowser-automationanti-botcloudflare-bypassjavascript-renderingdata-extractionheadless-browser

同类 Skill