trafilatura
Use Trafilatura for web text discovery, downloading, extraction, metadata, CLI batch processing, deduplication, and structured corpus outputs.
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-08
- Stars
- ★ 11
- Forks
- 3
01 前言 Front Matter
- name
- trafilatura
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Use Trafilatura for web text discovery, downloading, extraction, metadata, CLI batch processing, deduplication, and structured corpus outputs.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/package-overview.md5.2 KB
- 参考文档references/repo-provenance.md3.4 KB
- 参考文档references/repo-routing-metadata.json404 B
- 参考文档references/troubleshooting.md5.2 KB
03 SKILL.md 正文
Trafilatura Repo Skill
Use this skill when a task involves Trafilatura, or when the task is about extracting clean text and metadata from HTML, preparing web-corpus data, discovering article URLs from feeds/sitemaps/crawls, or using a Python/CLI web-scraping tool that outputs TXT, Markdown, JSON, CSV, HTML, XML, or XML-TEI.
Trafilatura is both a Python package and a command-line tool. It can fetch or accept HTML, isolate main text and metadata, preserve selected structure, process batches, deduplicate repeated text, and produce corpus-friendly outputs.
Before you start
- Install or verify the package:
python -m pip install trafilatura python - <<'PY' import trafilatura print(trafilatura.__version__) print(trafilatura.extract('<html><body><p>Hello from Trafilatura.</p></body></html>')) PY - If optional features are requested, install the relevant extra instead of assuming it is present:
trafilatura[all]for language detection, faster encoding/compression/date handling, SOCKS proxy support, andpycurl-based download fallback.trafilatura[eval]only for benchmark/evaluation comparisons; it is not needed for normal extraction.
- Run scripts/check_trafilatura_environment.py for a no-network import, CLI, extraction, metadata, and deduplication smoke check.
- Read references/repo-provenance.md when checking whether this skill matches a current checkout or before refreshing the skill.
- Read references/package-overview.md for the shared capability map, output formats, install extras, and common constraints.
- Use references/troubleshooting.md for install/import, CLI PATH, optional-extra, config, network, and routing failures that cross sub-skill boundaries.
Route by task
| User task or signal | Read |
|---|---|
In-memory Python extraction from HTML strings, bytes, Response objects, or LXML trees |
sub-skills/python-extraction/SKILL.md |
Choose extract(), bare_extraction(), extract_metadata(), html2txt(), baseline(), output formats, metadata, comments, tables, links, images, or Extractor options |
sub-skills/python-extraction/SKILL.md |
Use the trafilatura command, stdin, -u/--URL, URL lists, local directories, output directories, backups, --keep-dirs, --parallel, or --config-file |
sub-skills/cli-batch-processing/SKILL.md |
| Build shell commands for TXT/Markdown/JSON/HTML/XML/XML-TEI output or CLI metadata/dedup/precision/recall flags | sub-skills/cli-batch-processing/SKILL.md |
Download pages with fetch_url()/fetch_response(), inspect Response, manage polite URL queues, or troubleshoot SSL/proxy/timeouts |
sub-skills/discovery-downloads/SKILL.md |
Discover URLs from feeds, sitemaps, focused crawling, --feed, --sitemap, --crawl, --explore, --probe, --archived, --url-filter, or --list |
sub-skills/discovery-downloads/SKILL.md |
| Build a corpus, choose JSON/CSV/XML/XML-TEI, validate TEI/XML, deduplicate boilerplate, compute Simhash/fingerprints, or understand evaluation benchmarks | sub-skills/corpus-quality/SKILL.md |
Common decisions
- Use Python APIs when the workflow already has HTML in memory or needs downstream parsing and programmatic error handling.
- Use the CLI when the workflow is a shell pipeline, local HTML directory conversion, URL-list batch, or reproducible command recipe.
- Use discovery/download guidance before extraction when URLs must be found, filtered, throttled, or fetched politely.
- Use corpus-quality guidance when many pages must be validated, deduplicated, fingerprinted, or converted into analysis-friendly structured outputs.
- Treat live network access, large crawls, benchmark corpora, credentials, and optional extras as explicit runtime decisions. The bundled scripts are no-network checks.
Minimal Python extraction
from trafilatura import extract
html = """<html><body><article><h1>Title</h1><p>Main article text with enough content.</p></article></body></html>"""
text = extract(html, output_format="txt", include_comments=False)
if text is None:
# See python-extraction troubleshooting for size thresholds, recall mode, and fallbacks.
raise RuntimeError("Trafilatura found no usable main text")
Minimal CLI extraction
trafilatura --help
cat page.html | trafilatura --markdown --with-metadata --no-comments
trafilatura --input-dir html-pages --output-dir extracted --json --parallel 2
Scope boundaries
- Trafilatura can help discover and crawl within documented limits, but it is not a full anti-bot bypass, browser automation, authentication, JavaScript rendering, or web-scale crawler system.
- Optional language detection and some speed/download backends need optional extras; absence of those extras should be reported as a capability limit.
- Benchmark/evaluation workflows are intentionally separate from ordinary extraction because they require extra packages and larger data.
- Runtime guidance in this skill is self-contained and should not require reopening the source repository.
04 同仓库更多 Skills
obsidian-clipper-template-creator
Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.
obsidian-clipper-template-creator
Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.
python-api
Programmatic Object-Detection-Metrics API guidance for BoundingBox, BoundingBoxes, Evaluator, enums, coordinate conversion, AP/mAP semantics, and source-style import diagnostics.
file-evaluation
Folder-based PASCAL VOC AP/mAP evaluation from ground-truth and detection text files.
object-detection-metrics
Guides legacy Object-Detection-Metrics PASCAL VOC AP/mAP evaluation from detection text folders and direct Python API classes.
nx-workspace-patterns
Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.