Trafilatura is a Python package and command-line tool designed to gather text on the Web and simplify the process of turning raw HTML into structured, meaningful data. It includes all the necessary discovery and text-processing components to perform web crawling, downloads, scraping, and extraction of main texts, metadata, and comments. No database is required — output converts directly to commonly used formats, making it handy and modular from day one. Going from raw HTML to essential content alleviates many problems related to text quality: Trafilatura focuses on the actual content, avoids the noise caused by recurring elements like headers and footers, and makes sense of the data and metadata using selected information. The extractor strikes a balance between limiting noise (precision) and including all valid parts (recall). It is robust, actively maintained, and reasonably fast.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.
Key Features
Web Crawling & Discovery
Supports sitemaps (TXT, XML) and feeds (ATOM, JSON, RSS) with smart URL management including filtering and deduplication.
Flexible Input Sources
Processes live URLs, download queues, previously saved HTML files, and already-parsed HTML trees in parallel.
Robust Text Extraction
Extracts main text using common patterns and generic algorithms (jusText and readability), plus formatting such as paragraphs, titles, lists, quotes, and code blocks.
Rich Metadata Extraction
Pulls title, author, publication date, site name, categories, and tags from web pages automatically.
Multiple Output Formats
Outputs to TXT, Markdown, CSV, JSON, HTML, XML, and XML-TEI — pick whatever fits your pipeline.
Optional Add-ons
Language detection on extracted text, faster encoding detection, SOCKS proxy support, and additional compression algorithms are available as optional extras.
How It Works
Trafilatura operates in three stages:- Download —
fetch_url()retrieves the raw HTML from a URL, managing HTTP headers, redirects, and polite crawl delays. - Extract —
extract()identifies the main content block, strips boilerplate (navigation, ads, footers), and returns clean text or structured data. - Output — The result is serialised to your chosen format: plain text, Markdown, JSON with metadata, XML, XML-TEI, or CSV.
Software Ecosystem
Trafilatura is the centrepiece of a broader set of jointly developed packages for web data extraction and analysis:- htmldate — fast and accurate extraction of publication and modification dates from web pages.
- courlan — URL sampling, filtering, and management for crawling workflows.
- adblock-rs (via Python bindings) — ad and tracker URL filtering.
Trusted by the Community
Trafilatura is integrated into thousands of projects and is actively used by companies such as HuggingFace, IBM, and Microsoft Research, as well as academic institutions including the Allen Institute, Stanford, the Tokyo Institute of Technology, and the University of Munich.
Barbaresi, A. Trafilatura: A Web Scraping Library and Command-Line Tool for Text Discovery and Extraction, Proceedings of ACL/IJCNLP 2021: System Demonstrations, pp. 122–131. DOI: 10.18653/v1/2021.acl-demo.15
Get Started
Installation
Install Trafilatura with pip, add optional extras, and configure the CLI entry point.
Quickstart
Fetch a URL and extract clean text or structured JSON in under five minutes.