Trafilatura’s discovery module provides three complementary strategies for finding content URLs on a website: RSS/Atom feed extraction, XML sitemap traversal, and an autonomous focused web crawler. Together they let you build comprehensive link lists before downloading and extracting page 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.
find_feed_urls()
Attempts to discover and parse RSS, Atom, or JSON feeds for a given website, then extracts all article URLs from those feeds. If the input URL is already a feed, it is parsed directly. Otherwise, Trafilatura probes the page for <link rel="alternate"> elements and known feed URL patterns, fetches any discovered feeds, and returns the collected links.
A homepage URL or a direct feed URL (RSS, Atom, JSON Feed). When the URL points to a subpage rather than the homepage (i.e., it contains more path segments), Trafilatura applies a URL prefix filter so that only links matching that path are returned. On failure, it automatically retries against the site homepage.
An ISO 639-1 two-letter language code (e.g.,
"en", "fr"). When set, URL heuristics are used to filter out links that appear to belong to a different language version of the site.When
False (default), only URLs belonging to the same domain or closely related subdomains are returned. Set to True to also include links pointing to external domains (e.g., Feedburner, Google News).Number of seconds to wait between HTTP requests to the same website, respecting politeness conventions.
list[str] — a sorted, deduplicated list of article URLs found in the feeds. Returns an empty list if no feeds are discovered or no valid links are found.
Examples
sitemap_search()
Discovers and traverses XML sitemaps for a website to collect page URLs. Trafilatura first checks robots.txt for declared Sitemap: entries, then tries a list of common sitemap paths (sitemap.xml, sitemap_index.xml, etc.). Nested sitemap index files are followed recursively up to the max_sitemaps limit.
A homepage URL, a direct sitemap URL (ending in
.xml, .xml.gz, or sitemap), or any page URL. When a subpage URL is given, Trafilatura applies a URL prefix filter to the results. The function verifies that the base URL is reachable before starting.An ISO 639-1 two-letter language code. When set,
hreflang attributes in the sitemap are used to select only URLs for the target language. Falls back to URL-pattern heuristics when hreflang is absent.Allow links pointing to external domains. By default, only URLs on the same domain (or closely related subdomains) are kept.
Seconds to pause between sitemap fetch requests to the same host.
Maximum number of individual sitemap files to fetch and process. Acts as a safeguard against very large or circular sitemap trees.
list[str] — a list of page URLs collected from all discovered sitemaps. Returns an empty list if no sitemaps are reachable or the site is unreachable.
Examples
focused_crawler()
A lightweight, focused web crawler that starts from a homepage, follows internal links, and builds up a list of discovered URLs. It respects robots.txt, prioritizes navigation pages (category listings, tag pages, etc.) to maximize URL discovery, and supports optional language filtering.
The crawler operates statelessly via two lists: a todo list (URLs to visit next) and a known links list (all URLs seen so far). Both are returned after each call so you can resume crawling incrementally.
The starting URL for the crawl, preferably the homepage of a website (e.g.,
"https://www.example.com"). The crawler automatically fetches and processes this page to seed the link queue.Maximum number of pages to actually visit (fetch and process for links) during this call. The crawl stops when this limit is reached or the site is exhausted, whichever comes first.
Stop the crawl if the total number of discovered (known) URLs exceeds this value. Useful as a memory safeguard on very large sites.
A previously generated crawl frontier (list of URLs to visit). Pass the
todo return value from a prior call to resume an interrupted crawl.A list of previously discovered URLs (visited or not). Pass the
known_links return value from a prior call to avoid revisiting the same pages.An ISO 639-1 two-letter language code. When set, pages whose detected language does not match are skipped and their links are not followed. Requires
py3langid to be installed.A
configparser.ConfigParser instance with Trafilatura settings. Used to read the default sleep time between requests.A pre-parsed
urllib.robotparser.RobotFileParser object. When None, the crawler automatically fetches and parses robots.txt from the homepage domain.An XPath expression. Matching elements are removed from each fetched page’s HTML before link extraction. Useful for suppressing navigation menus or sidebars that would pollute the link queue.
list[str]— the remaining crawl frontier (URLs yet to be visited)list[str]— all known URLs discovered during the crawl (visited and unvisited)
is_still_navigation()
A simple helper that inspects the current crawl frontier and returns True if it still contains navigation or listing pages (e.g., category archives, tag pages, paginated indexes). Used to decide whether to keep crawling for more link discovery or switch to downloading article content.
The current crawl frontier — a list of URLs that have been discovered but not yet visited. Typically the first element of the tuple returned by
focused_crawler().bool — True if at least one URL in todo is classified as a navigation page (using courlan.is_navigation_page()); False if all remaining URLs appear to be leaf/article pages.
Example