Skip to main content

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.

Trafilatura ships with a robust command-line interface that requires no Python code. You can download web pages, extract their main text, process entire directories, batch-download URL lists, discover links from feeds and sitemaps, and crawl websites — all from the terminal. All commands are followed by pressing Enter. Use trafilatura -h to display the full help message at any time.

Basic Usage

Download and Extract a Single URL

# extract main text as plain text (default)
trafilatura -u "https://github.blog/2019-03-29-leader-spotlight-erin-spiceland/"

# extract with XML structure preserved
trafilatura --xml --URL "https://github.blog/2019-03-29-leader-spotlight-erin-spiceland/"

# display the help message
trafilatura -h

Pipe HTML from Standard Input

# process an existing local file
cat myfile.html | trafilatura

# alternative stdin syntax
< myfile.html trafilatura

# use a custom download tool and pipe to trafilatura
wget -qO- "https://de.creativecommons.org/index.php/was-ist-cc/" | trafilatura

Input Options

# -u / --URL: download and extract a single URL
trafilatura -u "https://www.example.org/article"
trafilatura --URL "https://www.example.org/article"
Trafilatura waits a few seconds between requests to the same domain by default. Some websites may block the requests user-agent after a high number of requests in a short period.

Output Options

# -o / --output-dir: write results to a directory (created if missing)
trafilatura -i list.txt -o results/

# --backup-dir: keep a copy of the original downloaded HTML
trafilatura --input-file links.txt --output-dir converted/ --backup-dir html-sources/ --xml

# --keep-dirs: mirror input directory structure in output (requires -o)
trafilatura --input-dir pages/ --output-dir results/ --keep-dirs

# --list: print discovered URLs without downloading or extracting them
trafilatura --feed "https://www.dwds.de/" --list
trafilatura --sitemap "https://www.sitemaps.org/" --list > mylinks.txt
When no --output-dir is specified, results are printed to standard output (STDOUT).

Trafilatura supports three link-discovery strategies: feeds (fresh content), sitemaps (exhaustive page lists), and crawling (following internal links).
# auto-detect feeds starting from a homepage
trafilatura --feed "https://www.dwds.de/" --list

# use a known feed URL directly
trafilatura --feed "https://www.dwds.de/api/feed/themenglossar/Corona" --list

# process a list of sources in parallel
trafilatura -i mylist.txt --feed --list

URL Filtering

Apply string-pattern filters to restrict which discovered URLs are processed or listed.
# only include URLs containing a specific path segment
trafilatura --sitemap "https://www.sitemaps.org/" --list --url-filter "https://www.sitemaps.org/de"

# filter by keyword pattern
trafilatura --sitemap "https://www.sitemaps.org/" --list --url-filter "protocol"

# using a subpath as the starting URL also acts as a filter
trafilatura --sitemap "https://www.sitemaps.org/de/" --list

Extraction Options

# -f / --fast: skip fallback extraction (approx. 2× faster)
trafilatura -u "https://www.example.org/article" -f
trafilatura -u "https://www.example.org/article" --fast
Certain elements are only visible in the output if the chosen format supports them (e.g. images require XML or XML-TEI). Including extra structural elements works best with --xml or --xmltei.

Format Selection

Choose an output format using a shorthand flag or the explicit --output-format option.
# plain text (default, no flag needed)
trafilatura -u "https://www.example.org/article"

# CSV
trafilatura -u "https://www.example.org/article" --csv

# HTML (v1.11+)
trafilatura -u "https://www.example.org/article" --html

# JSON
trafilatura -u "https://www.example.org/article" --json

# Markdown (v1.9+)
trafilatura -u "https://www.example.org/article" --markdown

# XML
trafilatura -u "https://www.example.org/article" --xml

# XML-TEI
trafilatura -u "https://www.example.org/article" --xmltei
Combining txt or csv with --formatting or --links automatically triggers Markdown output. Selecting --markdown always enables text formatting. The --formatting flag has no effect on JSON output.

TEI Validation

# --validate-tei: validate XML-TEI output against the TEI standard
trafilatura -u "https://www.example.org/article" --xmltei --validate-tei
trafilatura -i list.txt -o output/ --xmltei --validate-tei

Verbosity and Version

# -v: increase logging verbosity (INFO level)
trafilatura -u "https://www.example.org" -v

# -vv: maximum verbosity (DEBUG level)
trafilatura -u "https://www.example.org" -vv

# --version: print version information and exit
trafilatura --version

Full Argument Reference

trafilatura [-h] [-i INPUTFILE | --input-dir INPUTDIR | -u URL]
            [--parallel PARALLEL] [-b BLACKLIST] [--list]
            [-o OUTPUTDIR] [--backup-dir BACKUP_DIR] [--keep-dirs]
            [--feed [FEED] | --sitemap [SITEMAP] | --crawl [CRAWL] |
            --explore [EXPLORE] | --probe [PROBE]] [--archived]
            [--url-filter URL_FILTER [URL_FILTER ...]] [-f]
            [--formatting] [--links] [--images] [--no-comments]
            [--no-tables] [--only-with-metadata] [--with-metadata]
            [--target-language TARGET_LANGUAGE] [--deduplicate]
            [--config-file CONFIG_FILE] [--precision] [--recall]
            [--output-format {csv,json,html,markdown,txt,xml,xmltei} |
            --csv | --html | --json | --markdown | --xml | --xmltei]
            [--validate-tei] [-v] [--version]

Deprecated Arguments

The following CLI arguments have been removed. Use their replacements instead:
DeprecatedReplacement
--nocomments--no-comments
--notables--no-tables
--inputfile--input-file
--inputdir--input-dir
--outputdir--output-dir
-out--output-format
--hash-as-nameHashes are used by default
--with-metadata (old meaning)--only-with-metadata (only docs with required metadata)

Build docs developers (and LLMs) love