Skip to content

Quick Start

This guide walks through the three core operations: scrape (single page), crawl (follow links), and map (discover URLs). Each example is shown in multiple languages.


Scraping fetches one URL and returns its metadata, links, images, and markdown content.

src/main.rs
use crawlberg::{CrawlConfig, create_engine, scrape};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let engine = create_engine(Some(CrawlConfig::default()))?;
let result = scrape(&engine, "https://example.com").await?;
println!("Status: {}", result.status_code);
println!("Title: {}", result.metadata.title.as_deref().unwrap_or("(none)"));
println!("Description: {}", result.metadata.description.as_deref().unwrap_or("(none)"));
println!("Links: {}", result.links.len());
println!("Images: {}", result.images.len());
if let Some(ref md) = result.markdown {
let preview_len = 200.min(md.content.len());
println!("\n--- Markdown ({} chars) ---\n{}", md.content.len(), &md.content[..preview_len]);
}
Ok(())
}

The ScrapeResult includes:

  • status_code – HTTP response status
  • metadata – 40+ fields (Open Graph, Twitter Card, Dublin Core, JSON-LD, etc.)
  • links – all links categorized as Internal, External, Anchor, or Document
  • images – all image sources from <img>, <picture>, og:image, srcset
  • markdown – converted markdown with optional citations and fit content
  • feeds – discovered RSS, Atom, and JSON Feed links
  • json_ld – parsed JSON-LD entries

Crawling starts from a URL, follows links up to a configured depth, and returns results for all discovered pages.

src/main.rs
use crawlberg::{CrawlConfig, create_engine, crawl};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let engine = create_engine(Some(CrawlConfig {
max_depth: Some(2),
max_pages: Some(50),
stay_on_domain: true,
respect_robots_txt: true,
..Default::default()
}))?;
let result = crawl(&engine, "https://example.com").await?;
println!("Crawled {} pages (final URL: {})", result.pages.len(), result.final_url);
for page in &result.pages {
let title = page.metadata.title.as_deref().unwrap_or("(no title)");
let md_len = page.markdown.as_ref().map_or(0, |m| m.content.len());
println!(" [depth={}] {} - {} ({} chars markdown)", page.depth, page.url, title, md_len);
}
Ok(())
}

Key CrawlConfig fields for crawling:

Field Default Description
max_depth None (0) Maximum link hops from the start URL
max_pages None (unlimited) Maximum number of pages to crawl
max_concurrent None (10) Maximum parallel requests
stay_on_domain false Restrict crawling to the same domain
allow_subdomains false Allow subdomains when stay_on_domain is true
respect_robots_txt false Honor robots.txt directives
include_paths [] Regex patterns for paths to include
exclude_paths [] Regex patterns for paths to exclude

Mapping discovers all URLs on a site using sitemaps and link extraction, without downloading full page content.

src/main.rs
use crawlberg::{CrawlConfig, create_engine, map_urls};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let engine = create_engine(Some(CrawlConfig {
respect_robots_txt: true,
map_limit: Some(100),
..Default::default()
}))?;
let result = map_urls(&engine, "https://example.com").await?;
println!("Discovered {} URLs:", result.urls.len());
for entry in &result.urls {
let lastmod = entry.lastmod.as_deref().unwrap_or("(unknown)");
println!(" {} (last modified: {})", entry.url, lastmod);
}
Ok(())
}

Each SitemapUrl in the result includes:

  • url – the discovered URL
  • lastmod – last modification date (from sitemap, if available)
  • changefreq – change frequency hint (from sitemap)
  • priority – priority value (from sitemap)

  • Features – Full feature breakdown and competitive comparison
  • Configuration Reference – Complete CrawlConfig field reference
  • Guides – Browser automation, LLM extraction, custom strategies, and more