Incremental crawls and watch mode
Incremental crawling
Section titled “Incremental crawling”crawl -incremental (which implies --resume, and is also what watch mode uses) re-fetches every previously-crawled page and re-checks it for changes:
- Change detection is content-scoped: it hashes the extracted content-selector region, not the raw page. Churn in the page shell (navigation, analytics, build timestamps, CSRF tokens) outside the content selector does not count as a change.
- Pages whose content region is unchanged are skipped without re-converting, re-downloading images, or rewriting output. An unchanged page whose Markdown file is missing from the output is saved again.
- Pages whose content region changed are fully reprocessed and their output is rewritten.
- After an upgrade that changes the Markdown conversion, the first incremental crawl reprocesses every page once, since the output for the same HTML has changed.
- Unchanged pages still have their links followed, so a page newly linked from the navigation is found.
- A page a fresh crawl would no longer save is removed: one that returns 404 or 410, redirects to another URL (the new URL is saved instead), is disallowed by robots.txt, falls outside
allowed_domain,allowed_path_prefixordisallowed_path_patterns, is beyondmax_depth, is no longer HTML, or is now markednoindex. Its Markdown file, JSONL record and search entries go, anddiff_crawllists it as removed. Apart from redirects andnoindexpages, a removed page is fetched again only if a crawled page still links to it. Any other error (a 403 or a server error, for example) leaves its previously-crawled output as-is, and the page counts as unchanged when it comes back with the same content. A run that fails leaves everything in place. - Markdown files left under an older file name (after an upgrade renames pages) or by a removed page are deleted. Only files that start with doc-scraper’s page front matter are touched; other files you keep in the output directory stay.
- If every page fails and none checks out unchanged (the site is down, for example), or at least 3 pages and a quarter of the content pages fail with temporary errors, or the corpus would shrink by 30% or more on a site with at least 20 pages, the run is kept back and exits
3. The existing output is kept, and the run is not recorded in crawl history, soget_freshnessstill reports the last good crawl.watchtreats a kept-back run as failed and retries it after 15 minutes; pass-allow-shrinkto a one-offcrawlto accept a deliberate shrink.
Because there is no conditional-request support yet, incremental mode still performs the HTTP fetch for each known page; the savings come from skipping the downstream processing of unchanged pages.
Watch mode
Section titled “Watch mode”Watch mode enables scheduled periodic re-crawling of documentation sites. The scheduler tracks the last run time for each site and automatically triggers crawls when the configured interval has elapsed.
# Watch a single site with 24-hour interval./doc-scraper watch -site pytorch_docs -interval 24h
# Watch multiple sites./doc-scraper watch -sites pytorch_docs,tensorflow_docs -interval 12h
# Watch all configured sites weekly./doc-scraper watch --all-sites -interval 7dInterval Format
Section titled “Interval Format”The interval supports standard Go duration format plus day units:
30m- 30 minutes1h- 1 hour24h- 24 hours7d- 7 days1d12h- 1 day and 12 hours
Days must be whole (1.5d is rejected; write 1d12h), and the interval must be positive: 0, 0s, and negative values exit with an error. The same rules apply to interval in run task specs.
State Persistence
Section titled “State Persistence”Watch mode persists state to <state_dir>/watch_state.json, tracking:
- Last run time for each site
- Success/failure status
- Pages saved, re-checked but unchanged, and failed in the last run
- Error messages (if any)
This allows the scheduler to resume correctly after restarts, only running sites when their interval has elapsed. A failed run (the site was unreachable, every page failed, or the run was kept back for losing pages) is retried after 15 minutes instead of a full interval, or after the interval if that is shorter.
Each site’s state is saved as soon as its own crawl ends, so a fast site is recorded without waiting for the slowest one. A site whose crawl is still running is not started again on the next check, and a site being crawled by another process (for example a crawl in another terminal) is skipped without recording a failure; it runs on the first check after that crawl ends.
Example Output
Section titled “Example Output”First run of watch -site rust_cli_book -interval 24h (timestamps and the component=watch attribute trimmed from each line):
level=INFO msg="Starting watch mode for 1 sites with interval 24h0m0s"level=INFO msg="Watch schedule:"level=INFO msg=" rust_cli_book: never run, will run immediately"level=INFO msg="Running crawl for 1 due sites: [rust_cli_book]"...level=INFO msg=" rust_cli_book: SUCCESS - 17 pages saved, 0 unchanged, 0 failed, in 3.374338083s"...level=INFO msg="Next crawl: rust_cli_book in 24h0m0s (at 03:54:01 UTC)"After a restart, the schedule picks up from the saved state:
level=INFO msg="Starting watch mode for 1 sites with interval 24h0m0s"level=INFO msg="Watch schedule:"level=INFO msg=" rust_cli_book: last run 2026-10-15T03:54:01Z (success, 17 pages saved, 0 unchanged, 0 failed), next run 2026-10-16T03:54:01Z"level=INFO msg="Next crawl: rust_cli_book in 23h59m59s (at 03:54:01 UTC)"A later run with nothing changed on the site re-checks every page and reprocesses none:
level=INFO msg=" rust_cli_book: SUCCESS - 0 pages saved, 17 unchanged, 0 failed, in 168.335008ms"Output from doc-scraper 2.13.0, 2026-10-15; unchanged through 2.24.0.
Graceful Shutdown
Section titled “Graceful Shutdown”Watch mode handles SIGINT/SIGTERM gracefully: it stops the scheduler and cancels any in-progress crawl, letting the crawler flush its BadgerDB state and partial output first, so the interrupted crawl resumes cleanly on the next run. Watch exits 0 on a signal. A crawl interrupted this way is not recorded in the watch state, so the site is due as soon as watch starts again, and the crawl continues where it stopped. Only completed re-crawls are recorded in crawl history.