Skip to content
双引擎4 Commandscrawl4aiPythonv0.2.0

Web Scraper

双引擎网页抓取 + JS 交互 + SPA 渲染

L0 纯 HTTP + L1 crawl4ai 浏览器双引擎自动路由。三档内容精度控制,交互式内容提取(折叠展开/懒加载/JS 注入),exec 命令执行 JS。read_url_content 的完美替代方案。

Web Scraper
$./scrape discover https://cn.vuejs.org/api/
✅ Nav extraction: 61 URLs
交互式内容提取:展开折叠
$./scrape fetch https://open.feishu.cn/document/... --expand-all --wait 5000
OK 发送消息 - 服务端 API | 20,082 chars | ~5,020 tokens
JS 执行后抓取
$./scrape exec URL --js "expandAll()" --then-fetch -o /tmp/result.md
OK ✅ Saved → /tmp/result.md
$./scrape fetch --from-file urls.txt -o docs/
OK ✅ Saved 5 pages → docs/ (读取成员.md, 创建成员.md, ...)

核心能力

双引擎架构

L0 纯 HTTP (httpx + selectolax + markdownify) 毫秒级响应。L1 crawl4ai (Playwright) 处理 SPA 和反爬。Auto 模式自动路由。

内容精度三档

默认: PruningContentFilter 去除噪声。精准: --selector CSS 零噪声。原始: --raw 全页。

交互式内容提取

--expand-all 展开折叠、--scroll-full 懒加载、--js 自定义JS、--wait-for 等待元素。组合使用提取 SPA 动态内容。

JavaScript 执行

exec 命令:在页面上执行 JS 并返回结果。支持 --session 会话复用、--then-fetch JS 后抓取、--js-only 跳过导航。

智能站点发现

三层策略: sitemap.xml → HTML 导航 DOM 提取 → 浏览器深度爬取 (--deep)。

OpenAPI 提取

从 Swagger UI / spec URL 自动发现并转换为结构化 Markdown,含参数表、Schema、响应码。

命令参考

抓取 (fetch)

页面抓取与 Markdown 转换

命令说明示例
fetch单页抓取 (自动引擎)./scrape fetch https://open.feishu.cn/document/...
--engine cdp强制浏览器引擎./scrape fetch URL --engine cdp
--selector精准提取容器./scrape fetch URL --engine cdp --selector ".doc-body"
--expand-all展开所有折叠内容./scrape fetch URL --expand-all --wait 5000
--scroll-full全页滚动触发懒加载./scrape fetch URL --scroll-full
--js执行自定义 JS./scrape fetch URL --js "document.querySelectorAll('.btn').forEach(e => e.click())"
--js-file从文件执行 JS./scrape fetch URL --js-file /path/to/interact.js --wait 5000
--wait-for等待元素出现./scrape fetch URL --wait-for ".api-response-table"
--auto自动发现+抓取./scrape fetch https://docs.example.com --auto -o docs/
--from-file从 URL 列表抓取./scrape fetch --from-file urls.txt -o docs/
--merge合并为单文件./scrape fetch --from-file urls.txt --merge -o all.md
--raw全页输出./scrape fetch URL --raw
--summary-only仅显示摘要./scrape fetch URL --summary-only

JavaScript 执行 (exec)

在页面上下文中执行 JS 并取回结果

命令说明示例
exec执行 JS 返回结果./scrape exec URL --js "return document.title"
--then-fetchJS 后抓取为 Markdown./scrape exec URL --js "expandAll()" --then-fetch -o /tmp/result.md
--session ID复用浏览器会话./scrape exec URL --session mysession --js "getState()"
--js-only跳过导航 (已有会话)./scrape exec URL --js-only --session mysession --js "return data"

分析 (discover)

站点结构分析与链接提取

命令说明示例
discover站点分析./scrape discover https://docs.example.com
--deep浏览器深度爬取./scrape discover URL --engine cdp --deep --max-pages 100
--jsonJSON 输出./scrape discover URL --json

API 文档 (openapi)

OpenAPI/Swagger 规范提取

命令说明示例
openapi提取 API 文档./scrape openapi https://api.example.com/v3/api-docs -o api.md
从 Swagger UI自动发现 spec./scrape openapi https://api.example.com/swagger-ui/ -o api.md

何时使用

Agent 内置的 read_url_content 适用于简单静态页面,但在以下场景完全失败

  • SPA 页面(React、Vue、Angular — 内容由 JavaScript 渲染)
  • 现代文档站(VitePress、Docusaurus — 飞书、企业微信开发文档)
  • API 门户(Swagger UI、Redoc)
  • 折叠/懒加载内容(需要 JS 交互才能展示的内容)

内容精度控制

精度方式效果适用场景
默认无需额外参数PruningContentFilter 去除噪声大多数场景
精准--selector ".content"零噪声提取生产级文档
全页--raw完整页面调试分析

精准模式工作流:先抓样本页 → 分析残留噪声 → 识别 CSS 选择器 → 批量重抓。

使用场景

抓取 SPA 页面

bash
./scrape fetch https://open.feishu.cn/document/server-docs/im-v1/message/create

Auto 引擎自动探测到 SPA → 降级到 L1 浏览器 → 输出完整 Markdown。

交互式内容提取

对于折叠内容、懒加载页面、需要 JS 交互的场景:

bash
# 展开所有折叠/手风琴内容(通用预设)
./scrape fetch URL --expand-all --wait 5000

# 滚动触发懒加载
./scrape fetch URL --scroll-full

# 自定义 JS 点击展开按钮
./scrape fetch URL --js "document.querySelectorAll('.expand-btn').forEach(e => e.click())"

# 等待特定元素出现后再提取
./scrape fetch URL --wait-for ".api-response-table"

# 组合使用
./scrape fetch URL --expand-all --js "extraAction()" --wait-for ".loaded" -o /tmp/docs/

JavaScript 执行 (exec)

在页面上下文中执行 JS,提取运行时数据:

bash
# 提取页面的 JS 状态
./scrape exec URL --js "return JSON.stringify(window.__NEXT_DATA__)"

# 执行 JS 后再抓取页面
./scrape exec URL --js "expandAll()" --then-fetch -o /tmp/result.md

# 会话复用:多步交互
./scrape exec URL --session s1 --js "loginAndNavigate()"
./scrape exec URL --js-only --session s1 --js "return getData()"

批量下载文档站

bash
# 自动发现 + 批量抓取
./scrape fetch https://docs.example.com --auto -o /tmp/docs/

# 从 URL 列表抓取,合并为单文件
./scrape fetch --from-file urls.txt --merge -o /tmp/all.md

文件自动使用页面标题命名(读取成员.mdGetting_Started.md)。

构建本地文档库

  1. ./scrape discover <url> --json → 获取 URL + 标题
  2. Agent 筛选相关 URL → 写入文件
  3. ./scrape fetch --from-file urls.txt -o /path/to/docs/
  4. Agent 整理文件结构

关键选项

选项命令说明
--engine MODEdiscover, fetchauto (默认), http (仅L0), cdp (仅L1)
--selector CSSfetch, execCSS 选择器精准提取
--rawfetch, exec全页输出(跳过过滤)
--js CODEfetch, exec提取前执行 JS
--js-file PATHfetch, exec从文件执行 JS
--wait-for CSSfetch等待元素出现
--expand-allfetch展开折叠内容
--scroll-fullfetch滚动触发懒加载
--then-fetchexecJS 后抓取为 Markdown
--session IDexec复用浏览器会话
--js-onlyexec跳过导航 (已有会话)
--autofetch自动发现+抓取
--from-file FILEfetch从 URL 列表读取
--mergefetch合并为单文件
--jsondiscover, fetchJSON 输出
--summary-onlyfetch仅显示摘要
--max-pages Ndiscover, fetch限制页数
--deepdiscover浏览器深度爬取
-o PATHfetch, exec, openapi输出路径

前置条件

  • uv 包管理器:curl -LsSf https://astral.sh/uv/install.sh | sh
  • 首次运行自动安装 Python 依赖和 Playwright Chromium

架构

web-scraper/
├── scrape               ← Bash CLI 入口 (uv 环境自启动)
├── SKILL.md             ← Agent 指令文件
└── scripts/
    ├── engine.py        ← 双引擎核心 (L0 httpx + L1 crawl4ai)
    ├── scrape_cli.py    ← CLI 命令: discover / fetch / exec / openapi
    └── pyproject.toml   ← Python 依赖声明

依赖: crawl4ai (Playwright) | httpx | selectolax | markdownify

快速开始

Install
via skills.sh (推荐)
$npx skills add northseadl/norix-skills/web-scraper
或手动安装
$git clone https://github.com/northseadl/norix-skills.git
$ln -s norix-skills/web-scraper <SKILLS_DIR>/web-scraper
验证
$./scrape help
OK Skill ready.

Built for AI Agents, by Norix