trafilatura
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTrafilatura
Trafilatura
CLI skill for trafilatura: extract main article text and metadata from URLs, piped HTML, or local files. Follow the stdout-first protocol before any batch writes.
Scope: Single-page extraction, metadata JSON, piped/local HTML, bounded URL discovery (), and user-approved batch processing. NOT for: multi-source research (), PDF/tables (), raw page fetch (/), video hosts (), or paywall bypass.
--listresearchdoclingfetchfetcheryt-dlp用于trafilatura的CLI技能:从URL、管道HTML或本地文件中提取主要文章文本和元数据。在进行任何批量写入之前,请遵循标准输出优先协议。
**适用范围:**单页提取、元数据JSON输出、管道/本地HTML处理、有限范围的URL发现(参数)以及用户批准的批量处理。**不适用场景:**多源研究(工具)、PDF/表格处理(工具)、原始页面抓取(/工具)、视频平台处理(工具)或绕过付费墙。
--listresearchdoclingfetchfetcheryt-dlpCanonical Vocabulary
标准术语表
| Term | Meaning | NOT |
|---|---|---|
| extract | Single URL → clean text via CLI | full crawl harvest |
| metadata | JSON output with | bare URL probe only |
| pipe | Stdin or local | download from URL |
| discover | | bulk download |
| batch | | silent mass scrape |
| local | | live fetch |
| archived | | paywall bypass |
| precision | | default when content missing |
| recall | | default when noise high |
| doctor | Preflight JSON for binary and version | live URL smoke |
| 术语 | 含义 | 不包含 |
|---|---|---|
| extract | 单个URL → 通过CLI提取干净文本 | 全站点爬取收获 |
| metadata | 使用 | 仅探测裸URL |
| pipe | 以标准输入或本地 | 从URL下载内容 |
| discover | 结合 | 批量下载 |
| batch | 通过 | 静默大规模爬取 |
| local | 使用 | 实时抓取 |
| archived | 使用 | 绕过付费墙 |
| precision | 使用 | 内容缺失时的默认模式 |
| recall | 使用 | 冗余内容较多时的默认模式 |
| doctor | 预检查二进制文件和版本的JSON输出 | 实时URL可用性探测 |
Dispatch
命令调度
| Mode | Action |
|---|---|---|
| Doctor | Run |
| Extract | Stdout-first via |
| Metadata | |
| Pipe | |
| Discover | |
| Discover | |
| Discover | |
| Discover | |
| Batch | Approval gate → |
| Local | Approval gate → |
| Archived | |
| Natural language: "main text", "clean article", "extract from URL" | Auto | Map to extract (stdout-first) |
| (empty) | Help | Gallery + protocol + references |
| 模式 | 操作 |
|---|---|---|
| 诊断模式 | 执行 |
| 提取模式 | 通过 |
| 元数据模式 | 执行 |
| 管道模式 | 对文件或标准输入的HTML执行 |
| 发现模式 | 执行 |
| 发现模式 | 执行 |
| 发现模式 | 执行 |
| 发现模式 | 执行 |
| 批量模式 | 需确认权限 → 使用 |
| 本地模式 | 需确认权限 → 使用 |
| 归档模式 | 常规抓取失败后执行 |
| 自然语言指令:"main text"、"clean article"、"extract from URL" | 自动模式 | 映射到提取模式(优先输出到标准输出) |
| (空参数) | 帮助模式 | 展示示例、协议及参考文档 |
Auto-Detection Heuristic
自动检测规则
- URL + "sitemap", "feed", "crawl", "list URLs" → Discover (only).
--list - URL + "metadata", "title", "author", "date" → Metadata.
- Path to or "pipe", "stdin", "local file" → Pipe.
.html - Path to URL list file or "batch" → Batch (approval gate).
- Directory of saved HTML → Local (approval gate).
- "Archive", "wayback", "link rot" after failed fetch → Archived.
- Bare URL or "extract", "clean", "article text" → Extract.
- Ambiguous → ask: extract, metadata, discover list, or batch?
- URL + "sitemap"、"feed"、"crawl"、"list URLs" → 发现模式(仅返回链接列表)。
- URL + "metadata"、"title"、"author"、"date" → 元数据模式。
- 文件路径或包含"pipe"、"stdin"、"local file" → 管道模式。
.html - URL列表文件路径或包含"batch" → 批量模式(需确认权限)。
- 已保存HTML的目录路径 → 本地模式(需确认权限)。
- 抓取失败后出现"Archive"、"wayback"、"link rot" → 归档模式。
- 裸URL或包含"extract"、"clean"、"article text" → 提取模式。
- 指令模糊时 → 询问用户:提取、元数据、发现链接列表还是批量处理?
Stdout-First Protocol
标准输出优先协议
Run stages in order. Do not skip doctor after CLI errors. Do not batch-write until single-URL needs are met or the user explicitly approves bulk scope.
按顺序执行步骤。CLI报错后请勿跳过诊断步骤。在满足单URL需求或用户明确批准批量范围之前,请勿执行批量写入。
Stage 1 — Doctor (once per session or after errors)
步骤1 — 诊断(每次会话或报错后执行一次)
bash
uv run python scripts/doctor.py --format jsonStop on or any check with (missing binary).
ok: falsestatus: failtrafilaturabash
uv run python scripts/doctor.py --format json若返回或任何检查项(如缺少二进制文件),则停止操作。
ok: falsestatus: failtrafilaturaStage 2 — Extract (preferred for single URLs)
步骤2 — 提取(单URL优先选择)
bash
uv run python scripts/extract_url.py --url 'https://…' --format jsonMarkdown (default readable):
bash
uv run python scripts/extract_url.py --url 'https://…' --output-format markdownFrom probe JSON, report: , , (if metadata), , and format. Load references/output-formats.md when choosing formats.
urltitledatetext_lengthbash
uv run python scripts/extract_url.py --url 'https://…' --format json输出Markdown格式(默认易读):
bash
uv run python scripts/extract_url.py --url 'https://…' --output-format markdown从探测JSON中报告:、、(若包含元数据)、及输出格式。选择格式时可参考references/output-formats.md。
urltitledatetext_lengthStage 3 — Discover (list only by default)
步骤3 — 发现(默认仅返回链接列表)
bash
uv run python scripts/list_urls.py --mode sitemap --url 'https://…' --format jsonPresent and a sample of URLs. Do not chain into batch download without explicit user approval.
url_countbash
uv run python scripts/list_urls.py --mode sitemap --url 'https://…' --format json展示及URL示例。未经用户明确批准,请勿自动链式执行批量下载。
url_countStage 4 — Batch / local (explicit approval required)
步骤4 — 批量/本地处理(需明确批准)
Before running:
- Confirm URL count or directory scope.
- Confirm output directory (default: ).
$HOME/Downloads/trafilatura/output/ - Confirm politeness acknowledgment — see references/politeness-and-ethics.md.
bash
mkdir -p "$HOME/Downloads/trafilatura/output"
trafilatura -i list.txt -o "$HOME/Downloads/trafilatura/output/" --markdown --backup-dir "$HOME/Downloads/trafilatura/html-backup/"执行前需确认:
- URL数量或目录范围。
- 输出目录(默认:)。
$HOME/Downloads/trafilatura/output/ - 确认遵守礼貌规则 — 参考references/politeness-and-ethics.md。
bash
mkdir -p "$HOME/Downloads/trafilatura/output"
trafilatura -i list.txt -o "$HOME/Downloads/trafilatura/output/" --markdown --backup-dir "$HOME/Downloads/trafilatura/html-backup/"Stage 5 — Escalation (missing or blocked content)
步骤5 — 问题升级(内容缺失或被拦截)
- Retry with (CLI) or
--recallflag on--recall.extract_url.py - If download blocked: or
wget -qO- 'URL' | trafilatura.curl -sL 'URL' | trafilatura - If unavailable: or
extract_url.py --archived.trafilatura --archived -u 'URL' - If still empty: note JS-rendered page limitation — no in-tool browser automation. See references/troubleshooting.md.
- 使用参数重试(CLI或
--recall添加extract_url.py标志)。--recall - 若下载被拦截:或
wget -qO- 'URL' | trafilatura。curl -sL 'URL' | trafilatura - 若内容不可用:或
extract_url.py --archived。trafilatura --archived -u 'URL' - 若仍为空:说明存在JS渲染页面限制 — 工具内无浏览器自动化功能。参考references/troubleshooting.md。
MCP fallback (no Bash)
MCP备用方案(无Bash环境)
When doctor fails because the harness has no shell, use MCPHub → . Document degraded path. See references/mcp-fallback.md.
trafilaturafetch_and_extract若因环境无Shell导致诊断失败,使用MCPHub的 → 。记录降级路径。参考references/mcp-fallback.md。
trafilaturafetch_and_extractMode Details
模式详情
Extract
提取模式
- Use bundled (wraps
extract_url.py).trafilatura -u - Read-only regarding repo tree; stdout or JSON envelope only.
- Default output: markdown for human summary; json when structured metadata is needed.
- 使用内置的(封装
extract_url.py命令)。trafilatura -u - 仅读取仓库目录;仅输出到标准输出或JSON包。
- 默认输出:Markdown格式(供人工阅读);需要结构化元数据时输出JSON格式。
Metadata
元数据模式
bash
uv run python scripts/extract_url.py --url 'https://…' --output-format json --with-metadatabash
uv run python scripts/extract_url.py --url 'https://…' --output-format json --with-metadataPipe
管道模式
bash
trafilatura --markdown < page.html
cat page.html | trafilatura --json --no-tablesbash
trafilatura --markdown < page.html
cat page.html | trafilatura --json --no-tablesDiscover
发现模式
Modes: , , , . Always via unless user explicitly requests harvest.
feedsitemapcrawlprobe--listlist_urls.pyOptional filters: , (requires ). See references/discovery.md.
--url-filter--target-languagetrafilatura[all]支持模式:、、、。除非用户明确要求抓取,否则始终通过使用参数仅返回链接列表。
feedsitemapcrawlprobelist_urls.py--list可选过滤参数:、(需安装)。参考references/discovery.md。
--url-filter--target-languagetrafilatura[all]Batch
批量模式
- Parse list file (one URL per line).
- Require approval before runs.
-i - Recommend for HTML archival.
--backup-dir - Never write into the agents repo.
- 解析列表文件(每行一个URL)。
- 执行命令前需获得批准。
-i - 推荐使用参数归档HTML文件。
--backup-dir - 禁止写入代理仓库目录。
Local
本地模式
- for previously downloaded HTML.
--input-dir - Mirror structure with when needed.
--keep-dirs - Approval gate same as batch.
- 使用参数处理已下载的HTML文件。
--input-dir - 必要时使用参数保留目录结构。
--keep-dirs - 批准流程与批量模式相同。
Archived
归档模式
- Use when equivalent returns nothing.
fetch_url - Slow; best for small URL sets.
- 当等效的命令返回空内容时使用。
fetch_url - 速度较慢;适合小批量URL。
Doctor
诊断模式
bash
uv run python scripts/doctor.py --format jsonbash
uv run python scripts/doctor.py --format jsonHelp
帮助模式
Show dispatch table, stdout-first protocol, default paths, and reference index.
展示调度表、标准输出优先协议、默认路径及参考文档索引。
Gallery (Empty Arguments)
示例库(空参数)
| # | Task | Example |
|---|---|---|
| 1 | Preflight | |
| 2 | Extract article | |
| 3 | Metadata JSON | |
| 4 | Discover sitemap | |
| 5 | Pipe local HTML | |
| 6 | Archived fallback | |
Pick a number, a mode from the dispatch table, or paste a URL and say whether you need extract, metadata, or URL discovery.
| 序号 | 任务 | 示例 |
|---|---|---|
| 1 | 预检查 | |
| 2 | 提取文章 | |
| 3 | 输出元数据JSON | |
| 4 | 发现站点地图链接 | |
| 5 | 处理本地HTML管道 | |
| 6 | 归档备用提取 | |
选择序号、调度表中的模式,或粘贴URL并说明需要提取、元数据还是URL发现功能。
Critical Rules
核心规则
- Doctor before first extract in a session (or after CLI errors).
- Stdout-first for single URLs — use before filesystem batch writes.
extract_url.py - Discover list-only by default — present URL count; no auto bulk download.
- Explicit approval for batch/local — confirm scope, output dir, politeness.
- No paywall bypass coaching — see references/politeness-and-ethics.md.
- Not Fetch MCP primary — article main-text extraction belongs here when trafilatura is appropriate.
- Not research — multi-source synthesis uses .
/research - Not docling — PDFs and table-heavy documents use docling MCP.
- Not yt-dlp — video/audio hosts use .
/yt-dlp - Report provenance — URL, format, title/date if present, text length in summary.
- 每次会话首次提取前需执行诊断(或CLI报错后)。
- 单URL优先输出到标准输出 — 在执行文件系统批量写入前使用。
extract_url.py - 发现模式默认仅返回链接列表 — 展示URL数量;禁止自动批量下载。
- 批量/本地处理需明确批准 — 确认范围、输出目录及礼貌规则。
- 禁止指导绕过付费墙 — 参考references/politeness-and-ethics.md。
- 非Fetch MCP主工具 — 当trafilatura适用时,文章正文提取属于本工具范畴。
- 非研究工具 — 多源合成使用工具。
/research - 非docling工具 — PDF和表格密集型文档使用docling MCP工具。
- 非yt-dlp工具 — 视频/音频平台使用工具。
/yt-dlp - 报告来源信息 — 摘要中需包含URL、格式、标题/日期(若存在)及文本长度。
Troubleshooting
故障排除
See references/troubleshooting.md for precision/recall, archived fallback, wget/curl pipe, and JS-rendered pages.
关于精确/召回模式、归档备用方案、wget/curl管道及JS渲染页面的问题,请参考references/troubleshooting.md。
References
参考文档
| File | Use when |
|---|---|
| output-formats.md | Choosing txt/json/markdown/xml formats |
| discovery.md | Feed, sitemap, crawl, url-filter |
| troubleshooting.md | Missing content, blocked downloads |
| politeness-and-ethics.md | Robots, rate limits, refusals |
| mcp-fallback.md | Shell-less harness / MCPHub path |
| 文件 | 使用场景 |
|---|---|
| output-formats.md | 选择txt/json/markdown/xml输出格式时 |
| discovery.md | 处理Feed、站点地图、爬取、URL过滤时 |
| troubleshooting.md | 内容缺失、下载被拦截时 |
| politeness-and-ethics.md | 机器人协议、速率限制、拒绝规则相关 |
| mcp-fallback.md | 无Shell环境 / MCPHub路径相关 |
Scripts
脚本说明
| Script | Purpose |
|---|---|
| JSON preflight: trafilatura binary and version |
| Single-URL CLI wrapper with JSON envelope |
| Discovery |
| Validate skill manifest and evals |
| 脚本 | 用途 |
|---|---|
| JSON格式预检查:trafilatura二进制文件及版本 |
| 单URL CLI封装工具,输出JSON包 |
| 发现模式的 |
| 验证技能清单及评估内容 |
Examples
示例命令
bash
undefinedbash
undefinedPreflight
预检查
uv run python scripts/doctor.py --format json
uv run python scripts/doctor.py --format json
Extract (stdout-first)
提取(优先输出到标准输出)
uv run python scripts/extract_url.py --url 'https://github.blog/2019-03-29-leader-spotlight-erin-spiceland/' --output-format markdown
uv run python scripts/extract_url.py --url 'https://github.blog/2019-03-29-leader-spotlight-erin-spiceland/' --output-format markdown
Metadata JSON
输出元数据JSON
uv run python scripts/extract_url.py --url 'https://example.org' --output-format json --with-metadata
uv run python scripts/extract_url.py --url 'https://example.org' --output-format json --with-metadata
Discover sitemap URLs (list only)
发现站点地图URL(仅返回列表)
uv run python scripts/list_urls.py --mode sitemap --url 'https://www.sitemaps.org/' --format json
uv run python scripts/list_urls.py --mode sitemap --url 'https://www.sitemaps.org/' --format json
Pipe local HTML
处理本地HTML管道
trafilatura --markdown < saved.html
trafilatura --markdown < saved.html
Batch (after user approval)
批量处理(用户批准后)
trafilatura -i urls.txt -o "$HOME/Downloads/trafilatura/output/" --markdown --backup-dir "$HOME/Downloads/trafilatura/html-backup/"
undefinedtrafilatura -i urls.txt -o "$HOME/Downloads/trafilatura/output/" --markdown --backup-dir "$HOME/Downloads/trafilatura/html-backup/"
undefined