crawler#
A small, dependency-minimal Rust web crawler that fetches a seed URL, extracts same-host links from the homepage, and saves HTML responses to disk.
๐ What it does#
- Accepts a seed URL (or hostname) as CLI input
- Fetches the homepage once
- Extracts
<a href="...">links in the first page - Normalizes each link to an absolute URL
- Follows only same-host links
- Fetches each same-host page once
- Saves each response body in
out_dirusing a deterministic URL hash filename - Logs crawl events to stdout with status and byte counts
๐งฉ Project structure#
src/main.rs- CLI entrypoint usingclap+tokiosrc/lib.rs- exposes reusable crawler APIsrc/engine.rs- crawl orchestrationsrc/fetch.rs- HTTP fetch wrapper withreqwestsrc/links.rs- HTML link extractionsrc/storage.rs- file path generation, save HTMLsrc/url_util.rs- URL normalization and same-host checkssrc/log.rs- logging abstraction (stdout + pluggable)
โถ๏ธ Usage#
Build and run from project root:
cargo run --release -- "https://example.com" --out-dir crawl_outShort form:
cargo run --release -- example.com -o crawl_outDefaults:
out_dir:crawl_out
๐ฆ Output#
crawl_out/<url_hash>.htmlurl_hashis derived from normalized final URL- stdout log events include:
seed,response,fetch,save,skip_links,link_skip,fetch_err,save_err
๐ ๏ธ Configuration#
No configuration file. Use CLI args only.
๐งช Tests#
No test files are currently included. The library is unit-test-friendly via Crawler::with_logger and CrawlConfig.
๐ฆ Dependencies#
reqwest(HTTP client)tokio(async runtime)anyhow(error handling)clap(CLI)url(URL parsing)
๐ก Extending#
- add depth control (breadth-first / recursive crawl)
- add robots.txt + rate limiting
- add concurrency queue and dedupe URL set
- add filter rules (patterns, content types)
- instrument with structured logging / metrics
๐ Notes#
The crawler is intentionally simple, for learning and small local crawl tasks. It is not a production spider and does not enforce politeness controls by default.