Trafilatura’s tutorials cover practical scenarios from discovering and filtering web content to building corpora, generating word frequency lists, and validating structured XML data. Whether you work on the command-line or in Python, these guides walk you through complete end-to-end workflows.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.
A Jupyter notebook covering core concepts interactively is available in the documentation repository:
Trafilatura_Overview.ipynb.Tutorial overview
Content Discovery & URL Management
Learn how to discover content using sitemaps, RSS/Atom feeds, and web crawling. Filter and manage URL lists with courlan before bulk downloading.
Word Frequency Lists & Text Analysis
Go from a list of URLs to a ranked frequency list. Tokenize with SoMaJo, filter stopwords, and compute n-gram statistics using command-line tools.
TEI XML Validation
Produce and validate TEI-compliant XML files. Use Trafilatura to extract content in the TEI standard and check documents against the TEI schema.
Vector Search & Text Embedding
Use Trafilatura with a vector database (Epsilla) to perform text embedding and semantic search over crawled web content.
DWDS Corpus Replication
Replicate DWDS web corpus data by exporting URLs from the DWDS portal and downloading them with Trafilatura (German-language tutorial).
Tutorial 1: Gathering a custom web corpus
This tutorial covers how to discover, filter, and download web content systematically — from finding URLs to storing extracted text files.Get your system up and running
Install Trafilatura
See the installation page for full instructions.
Understand the command-line interface
All following examples use the command-line interface. If you are new to the CLI, review the introduction on that page first.
Content discovery
Web sources used by Trafilatura can consist of previously known or listed pages. Trafilatura supports three methods to discover content within a website:- Sitemaps — XML files that list all available URLs for a site, intended for search engines
- Web feeds — Atom and RSS feeds providing recently updated content
- Web crawling — Hopping from page to page following internal links
Gathering links from the command-line
The--list flag outputs discovered URLs without downloading them — useful for inspecting what you will collect before committing to a full download.
For Python-based feed and sitemap usage, see the blog post Using RSS and Atom feeds to collect web pages with Python.
Link filtering
Before downloading at scale, it pays to inspect and filter your URL list to remove unwanted or redundant content.Filtering with courlan
Thecourlan package is installed automatically with Trafilatura. It separates text-rich HTML pages from spam, ads, and non-content URLs:
Custom filtering with grep
Usegrep for pattern-based inclusion or exclusion:
Sorting, deduplication, and sampling
Trafilatura automatically deduplicates and sorts the input list to optimize the download order, so manual sorting is not required.
Process a list of links
Seamless download and extraction
Two main options control batch processing:-i/--input-file— path to a file containing one URL per line-o/--output-dir— directory to write the extracted files into--backup-dir— (optional) keep a copy of the raw downloaded HTML
Using existing archives
If you already have downloaded HTML files, process them directly:Tutorial 2: Word frequency lists and text analysis
This tutorial shows how to go from a list of URLs all the way to a ranked word frequency list and n-gram statistics.Additional requirement: SoMaJo tokenizer
Build frequency lists
N-gram lists
Bigrams and trigrams reveal how words co-occur in a corpus.Working with XML output
If you extracted XML files instead of plain text, SoMaJo can process them directly:Further reading on text analysis
- Unix™ for Poets — count/sort words, compute n-gram statistics, build concordances
- Collocations HOWTO (NLTK)
- Analyzing Documents with TF-IDF (Programming Historian)
Tutorial 3: TEI XML validation
Trafilatura can produce and validate TEI-compliant XML files — an important standard for encoding cultural heritage and linguistic data.Producing TEI files
Validating existing TEI files
For a detailed walkthrough, see the blog post: Validating TEI-XML documents with Python.
Tutorial 4: Vector search and text embedding
This tutorial shows how to use Trafilatura together with Epsilla, an open-source vector database, to perform text embedding and semantic search over crawled web content. The same approach applies to alternative vector databases such as Qdrant, Redis, and ChromaDB.A hands-on version of this tutorial is available as a Colab Notebook.
Why perform text embedding with crawled data?
Text embedding converts text into numerical vectors commonly used for:- Search — rank results by a query string
- Clustering — group text strings by similarity
- Anomaly detection — identify outliers
Setup
Start an Epsilla server locally with Docker:Connect and create a table
Crawl pages and store embeddings
Perform vector search
Tutorial 5: DWDS corpus replication
This tutorial (in German) explains how to replicate data from the DWDS (Digitales Wörterbuch der deutschen Sprache) web corpus using Trafilatura. It covers exporting URL lists from the DWDS portal and downloading the corresponding pages for independent storage and analysis.The full tutorial is available in German in the Trafilatura documentation: tutorial-dwds.
- Search the DWDS corpus portal and export URLs as a TSV file
- Extract the URL column from the export
- Use
trafilatura -i urls.txt -o corpus/to download and extract the pages
Blog posts
View all related blog posts
View all related blog posts
Video tutorials
A YouTube playlist covering web scraping how-tos and tutorials in several languages is available: Web scraping how-tos and tutorials →External resources
- GLAM-Workbench — cultural heritage and web archives
- User Ethics & Legal Concerns — Melanie Walsh’s introduction to ethical web data collection
- Download von Web-Daten and Daten aufbereiten und verwalten — Tutorials in German by Noah Bubenhofer