trafilatura
Use Trafilatura for web text discovery, downloading, extraction, metadata, CLI batch processing, deduplication, and structured corpus outputs.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
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 资源文件 5
- 参考文档references/package-overview.md5.2 KB
- 参考文档references/repo-provenance.md3.4 KB
- 参考文档references/repo-routing-metadata.json404 B
- 参考文档references/troubleshooting.md5.2 KB
- 脚本scripts/check_trafilatura_environment.py5.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
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).