feat: respect robots.txt before fetching pages#8
Merged
Conversation
Production-grade crawlers check robots.txt. deepdive's per-query fetch volume is low (~12 URLs) but it's still the polite thing; sites with explicit scraper deny rules shouldn't be surprised. Behavior: - Before every agent.fetchOne, we check <scheme>://<host>/robots.txt with User-Agent "deepdive-bot" (configurable via AgentConfig.robotsUserAgent). - On "deny", skip the URL + emit a new fetch.skipped event so --verbose output shows the skip reason. - On "allow" or "unknown", proceed as before. - robots.txt content is cached in-memory per run (one GET per origin). - Network errors fetching robots.txt err on the side of "fetch" rather than "deny" — publishers who care have working robots.txt. Opt-out: --ignore-robots / DEEPDIVE_IGNORE_ROBOTS=1 bypasses the check entirely (for operators with their own relationship to the target). Parser supports: User-agent blocks (case-insensitive substring match, exact agent beats *), Disallow + Allow with longest-prefix wins (ties go to Allow per RFC 9309), empty Disallow = allow everything, wildcard * in paths, $ end-anchor, Crawl-delay field, # comments. Tests: 17 new assertions (12 parser unit, 5 canFetch integration, 2 CLI). 198 total.
This was referenced Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Production-grade crawlers check robots.txt. deepdive's per-query fetch volume is low (~12 URLs) but it's still the polite thing; sites with explicit scraper deny rules shouldn't be surprised.
Behavior
Before every
agent.fetchOne, check<scheme>://<host>/robots.txtwith User-Agentdeepdive-bot:fetch.skippedeventunknown(err on the side of fetching; publishers who care have working robots.txt)robots.txt content is cached in-memory per run (one GET per origin).
Opt-out
--ignore-robots/DEEPDIVE_IGNORE_ROBOTS=1bypasses entirely — for operators with their own relationship to the target.Parser
*)Disallow+Allowwith longest-prefix wins, ties go to Allow (RFC 9309)Disallow:grants everything*in paths,$end-anchorCrawl-delayfield captured (not yet enforced — would need per-host pacing in the fetch worker-pool)#comments strippedNew library exports
canFetch,createRobotsCache,parseRobotsTxt,isPathAllowed,DEFAULT_USER_AGENT, and typesRobotsCache,ParsedRobots,RobotsCheckResult,CanFetchOptions.Test plan
npm run build— clean under strict: truenpm test— 181 pass (up from 164), 0 fail*, UA substring+case-insensitive, comments, empty-Disallow grants, wildcard+$patterns, Crawl-delay captured, malformed lines skipped