Trafilatura provides robust HTTP downloading functionality through theDocumentation 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.downloads module. Whether you need a single decoded HTML string or a full response object with headers, the library handles connection pooling, retries, SSL, and domain-aware throttling automatically.
Simple Downloads
Thefetch_url() function is the easiest way to download a web page. It sends an HTTP GET request and returns the page content as a decoded Unicode string, or None if the download fails or the response doesn’t meet size requirements.
fetch_url() uses a connection pool internally, keeping connections open across calls for efficiency. You may see warnings in logs about this — they can safely be ignored.The Response Object
For richer access to the HTTP response — including status codes, headers, and raw binary data — use fetch_response(). It returns a Response object with the following attributes:
| Attribute | Type | Description |
|---|---|---|
data | bytes | Raw response body as a bytestring |
headers | dict | None | Response headers (populated when with_headers=True) |
html | str | None | Decoded HTML string (populated when decode=True) |
status | int | HTTP status code |
url | str | Final URL after any redirects |
fetch_response() was introduced in version 1.7.0. Use fetch_url() for a simpler interface when you only need the HTML string.Parallel Downloads
For bulk collection, Trafilatura provides a domain-aware parallel download system backed by threads. This is the recommended approach when retrieving pages from multiple different websites at once, as it throttles requests per domain to avoid overloading any single server.Convert your URL list to the internal format
add_to_compressed_dict() deduplicates URLs and organises them by domain into a UrlStore object.Draw a download buffer respecting back-off rules
load_download_buffer() draws a batch of URLs that are safe to fetch now, waiting if all remaining URLs are in their back-off window.Dispatch downloads with a thread pool
buffered_downloads() fans out the buffer list across the specified number of threads and yields (url, result) pairs as they complete.CLI Parallel Downloads
On the command line, Trafilatura automatically uses threads and domain-aware throttling. Pass a file of URLs with-i/--input-file and specify an output directory with -o:
Internet Archive Fallback
When a page cannot be fetched directly, Trafilatura can fall back to a cached version in the Internet Archive (Wayback Machine). Enable this with the--archived flag on the CLI:
https://web.archive.org/web/20/ and re-queued for download.
Politeness Rules
Politely behaved crawlers respect the servers they visit. Trafilatura implements several mechanisms to keep resource usage acceptable.Robots Exclusion Standard
Therobots.txt file at the root of a website describes which parts may be crawled and at what rate. Use Python’s built-in urllib.robotparser to read and enforce these rules:
Spacing Requests
Passsleep_time (in seconds) to load_download_buffer() to enforce a minimum interval between successive requests to the same domain:
SOCKS Proxy
Set thehttp_proxy environment variable before importing Trafilatura to route all downloads through a SOCKS proxy:
trafilatura.downloads.PROXY_URL at runtime (affects the current Python session only).
SOCKS proxy support was introduced in version 1.12.2.
Configuration
Download behaviour is controlled via asettings.cfg file. The relevant keys live in the [DEFAULT] section:
Custom User-Agents and Cookies
When asettings.cfg file with non-default values is loaded, fetch_url() and fetch_response() automatically pick up the configured user-agent and cookie:
USER_AGENTS, one is selected at random for each request, which can reduce the likelihood of rate-limiting.
Connection Pooling
Trafilatura reuses a singleurllib3.PoolManager (up to 50 pools) for the lifetime of the Python process. This means TCP connections to the same host are kept alive across multiple fetch_url() calls, reducing latency and overhead for sequential downloads to the same domain. When pycurl is installed, a shared CurlShare object provides additional DNS and SSL session caching.