Trafilatura simplifies the process of turning raw HTML into structured, meaningful data. This guide walks you through the core workflow — from installation to your first extraction — using both the Python API and the command-line interface.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/adbar/trafilatura/llms.txt
Use this file to discover all available pages before exploring further.
Install Trafilatura
Install Trafilatura from PyPI using pip:Verify the installation:For full installation options, optional extras, and troubleshooting, see the Installation guide.
Fetch and extract text with Python
The two core functions are
fetch_url() to download a page and extract() to pull out the main content. The only required argument to extract() is the downloaded HTML — everything else is optional.extract() strips boilerplate — navigation menus, ads, headers, footers — and returns only the article body and, by default, any reader comments.Customise the output format
Trafilatura supports several output formats and lets you include or exclude specific content elements:Available output formats are
txt (default), markdown, csv, json, html, xml, and xmltei.Fast Mode
By default, Trafilatura uses multiple extraction algorithms as fallbacks to maximise recall. If speed is a priority and you are comfortable with a potential minor drop in coverage, enable fast mode to skip the fallback algorithms:Extract All Text with html2txt
If you need all visible text on a page — rather than just the main content block — use html2txt. This is similar to tools like html2text but operates on an already-downloaded HTML string:
Extract Metadata Only
Useextract_metadata() to retrieve structured metadata (title, author, date, site name, etc.) without the full body text:
Bare Extraction (Low-Level)
bare_extraction() returns a Python dictionary directly, without serialisation to a string format. This is the most efficient option when you are processing results programmatically: