Skip to main content
The crawler module provides the core crawling functionality for the llms.txt Generator. It handles webpage fetching, content extraction, and intelligent fallback between httpx and Bright Data Scraping Browser.

Overview

The LLMCrawler class crawls websites starting from a base URL, extracting meaningful content from each page. It supports:
  • Sitemap-based crawling (tries /sitemap.xml and /sitemap_index.xml)
  • Breadth-first search (BFS) fallback when no sitemap exists
  • Dual-fetching strategy: httpx → Bright Data Scraping Browser
  • Content validation to detect blocked/empty responses
  • Configurable page limits and description lengths

Classes

PageInfo

Data class representing extracted information from a single page.
str
required
The full URL of the page
str
required
Extracted page title (from <title> or <h1>)
str
required
Page description (from meta tags or content)
str
required
Truncated text snippet from page content

LLMCrawler

Main crawler class that orchestrates the crawling process.

Constructor

str
required
The starting URL to crawl (will be normalized)
int
required
Maximum number of pages to crawl
int
required
Maximum length for generated snippets
Callable
required
Async function for logging progress (receives string messages)
str | None
default:"None"
API key for Bright Data Scraping Browser
bool
default:"True"
Whether to enable Bright Data fallback
str
default:"scraping_browser1"
Bright Data zone to use
str | None
default:"None"
Optional password for Bright Data authentication

Methods

run()
Executes the crawl and returns extracted page information.
list[PageInfo]
List of successfully crawled pages with extracted content
Behavior:
  1. Attempts to load sitemap (/sitemap.xml or /sitemap_index.xml)
  2. If sitemap exists, uses those URLs; otherwise performs BFS crawl
  3. For each URL:
    • First tries httpx (fast)
    • Validates content for meaningful data
    • Falls back to Bright Data if needed
    • Extracts title, description, and text
    • Discovers and queues new links
  4. Stops when max_pages reached or queue exhausted
  5. Attempts up to max_pages * 3 URLs to handle failures
  6. Logs usage stats if Bright Data was used

Usage Examples

Basic Crawl

With Bright Data Fallback

Sitemap-First Crawl

Fetching Strategy

The crawler uses a two-tier fetching strategy:

Tier 1: httpx (Fast)

  • Uses standard HTTP client with 10s timeout
  • Follows redirects automatically
  • Validates response has meaningful content
  • Most cost-effective approach

Tier 2: Bright Data Scraping Browser (Reliable)

  • Triggered when httpx fails or returns empty content
  • Executes JavaScript, handles anti-bot measures
  • More expensive but handles difficult sites
  • Usage tracked and reported at end of crawl

Content Validation

The has_meaningful_content() function checks for:
  • Non-empty body content
  • Absence of common blocking indicators
  • Minimum content threshold
  • scout - URL normalization, link extraction, sitemap parsing
  • text - Title/description/text extraction and snippet creation
  • scraping_browser_client - Bright Data Scraping Browser integration
  • state - Crawl state management (queue, visited set)

Notes

  • All URLs are normalized before processing
  • Visited tracking prevents duplicate crawls
  • Queue implements BFS traversal
  • Graceful degradation: continues even if some pages fail
  • Warning logged if fewer pages found than requested