# Trafilatura

> Crawl the web and pull clean main text and metadata out of messy HTML

- Category: Data & Labeling / Web Scraping & Crawling
- Language: Python
- Licence: Apache-2.0
- Repository: https://github.com/adbar/trafilatura
- Website: https://trafilatura.readthedocs.io
- Canonical page: https://ai-tldr.dev/tools/trafilatura/

## In short

Trafilatura is a Python package and command-line tool for gathering text on the web and turning raw HTML into structured data. It handles the full path from discovery to output: crawling, downloading, scraping, and extracting the main text, metadata, and comments from a page. It sits in the Web Scraping & Crawling category of the Data & Labeling tools and is open-source, written in Python and licensed Apache-2.0.

## Overview

Trafilatura is a Python package and command-line tool for gathering text on the web and turning raw HTML into structured data. It handles the full path from discovery to output: crawling, downloading, scraping, and extracting the main text, metadata, and comments from a page.

It is built for developers and researchers who need clean article content without the surrounding noise. By focusing on the actual content and dropping recurring elements like headers and footers, it produces text that is easier to feed into search indexes, datasets, or NLP pipelines. No database is required, and the output converts to common formats.

Within web scraping and crawling tools, Trafilatura sits at the extraction layer. It supports sitemaps and feeds for finding URLs, processes both live and previously downloaded HTML, and can emit TXT, Markdown, CSV, JSON, HTML, XML, and XML-TEI.

## What it does

- Extracts main text plus metadata such as title, author, date, site name, categories, and tags
- Discovers content through sitemaps (TXT, XML) and feeds (ATOM, JSON, RSS) with URL filtering and deduplication
- Processes both live URLs and previously downloaded HTML files or parsed trees, with parallel download queues
- Preserves structure: paragraphs, titles, lists, quotes, code, line breaks, and inline formatting, plus optional comments, links, images, and tables
- Outputs TXT, Markdown, CSV, JSON, HTML, XML, and XML-TEI
- Optional add-ons for language detection on extracted content and speed optimizations

## Getting started

Install the package, then extract main text from a URL using either the command line or the Python API.

1. Install Trafilatura

   Install the package from PyPI with pip.

```bash
pip install trafilatura
```

2. Extract from the command line

   Pass a single URL with the -u flag to print its main text.

```bash
trafilatura -u "https://github.blog/2019-03-29-leader-spotlight-erin-spiceland/"
```

3. Extract with Python

   Use fetch_url to download a page and extract to get its main text.

```python
from trafilatura import fetch_url, extract

downloaded = fetch_url('https://github.blog/2019-03-29-leader-spotlight-erin-spiceland/')
result = extract(downloaded)
print(result)
```

## When to use it

- Building text datasets from many web pages for research or NLP and LLM training
- Cleaning article content for search indexing or a reading or archiving pipeline
- Crawling a site through its sitemap or feed and exporting articles to JSON, CSV, or Markdown
- Pulling page metadata like author, date, and title alongside the body text
