Principle:1broseidon Ketch BFS Crawl
| Knowledge Sources | |
|---|---|
| Domains | Crawl, Graph_Traversal |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
A breadth-first traversal of same-host links from a seed URL, bounded by a max depth and a worker pool, that reuses the shared scrape pipeline for each page.
Theoretical Basis
BFS explores pages in order of distance from the seed: depth-0 pages first, then their same-host links at depth 1, and so on, up to `opts.Depth`. The crawler keeps a mutex-guarded `visited` map for dedup and a buffered work channel drained by a worker pool (default 8). Each enqueued item is normalized, filtered (allow substrings / deny regexps), validated, and rewritten before it joins the queue, so the visited-set and cache key are canonical.
Link discovery runs only for BFS (not sitemap mode): the page's goquery doc (reused from the scrape) yields same-host links, which are enqueued at `parent.depth+1`. A `Result` is delivered per page via a callback, so foreground (stream to stdout), background (write status JSON), and MCP (collect with caps) modes share one engine.
Sitemap mode seeds the queue from the sitemap's URLs at depth 0 instead of discovering links, so a site that exposes a sitemap is crawled without link parsing.
Usage
Use when you need to gather many pages from one site in a bounded, deduplicated traversal. Use sitemap mode when the site publishes one. Bound with depth + concurrency + filters to keep the crawl focused.