Respecting robots.txt is the baseline of responsible web scraping and crawling, and since September 2022 it has had a formal IETF standard, RFC 9309. But a crawler only respects robots.txt as well as its parser reads it. Read a file wrongly in one direction and you crawl pages a site asked you not to; read it wrongly in the other and you miss pages you were allowed to fetch. We ran 20 test cases built from the RFC through four Python parsers. One got all 20 right. The one built into Python got 12.
The rules that trip parsers up
Most robots.txt files are simple, but RFC 9309 sets precise rules for the cases that are not:
- Longest match wins. “The most specific match found MUST be used. The most specific match is the match that has the most octets.” The order of the lines does not matter.
- Ties go to Allow. “If an ‘allow’ rule and a ‘disallow’ rule are equivalent, then the ‘allow’ rule SHOULD be used.”
- Wildcards are required. Crawlers “MUST support”
*, meaning any characters, and$, meaning the end of the path. - User-agent matching ignores case, and if several groups name the same bot, their rules “MUST be combined into one group”.
- Percent-encoded letters are decoded before comparison, so
/%62%61%7Amatches a rule for/baz. - robots.txt itself is always allowed, and rules that appear before any user-agent line should be ignored.
The test
We tested four parsers in Python 3.11:
| Parser | Version | Notes |
|---|---|---|
| urllib.robotparser | Python 3.11 standard library | Built in |
| robotexclusionrulesparser | 1.7.1 | An older third-party parser |
| robotspy | 0.13.0 | Calls itself a Robots Exclusion Standard parser |
| Protego | 0.7.0 | Scrapy’s default robots.txt parser |
Each case pairs a small robots.txt file with a URL and the answer RFC 9309 requires, for a crawler called ExampleBot. Every case comes from a rule or example in the RFC itself.
The results
| Parser | Correct, of 20 | Too permissive | Too strict |
|---|---|---|---|
| Protego | 20 | 0 | 0 |
| robotspy | 18 | 1 | 1 |
| robotexclusionrulesparser | 14 | 2 | 4 |
| urllib.robotparser | 12 | 4 | 4 |
“Too permissive” means the parser allowed a URL the file blocks, which is the error that matters most: your crawler fetches pages the site asked it to leave alone. “Too strict” means it blocked a URL the file allows.
Case by case, with ✓ for the RFC answer and ✗ for a wrong one:
| Case | RFC | urllib | rerp | robotspy | Protego |
|---|---|---|---|---|---|
| Longer Allow beats shorter Disallow | Allow | ✗ | ✗ | ✓ | ✓ |
| Same rules, Allow listed first | Allow | ✓ | ✓ | ✓ | ✓ |
| Longer Disallow beats shorter Allow | Block | ✗ | ✗ | ✓ | ✓ |
| Equal Allow and Disallow | Allow | ✗ | ✗ | ✓ | ✓ |
Disallow: /*.pdf | Block | ✗ | ✓ | ✓ | ✓ |
Disallow: /*.pdf$, URL with a query | Allow | ✓ | ✓ | ✓ | ✓ |
Disallow: /*.pdf$, exact | Block | ✗ | ✓ | ✓ | ✓ |
| User-agent in another case | Block | ✓ | ✓ | ✓ | ✓ |
| User-agent with a version | Block | ✓ | ✓ | ✗ | ✓ |
| Two groups for the same bot | Block | ✗ | ✗ | ✓ | ✓ |
Bot’s own group replaces * | Allow | ✓ | ✓ | ✓ | ✓ |
| Another bot’s group | Allow | ✓ | ✓ | ✓ | ✓ |
| Several user-agent lines | Block | ✓ | ✓ | ✓ | ✓ |
| Empty Disallow | Allow | ✓ | ✓ | ✓ | ✓ |
Allow: /$ for the homepage | Allow | ✗ | ✗ | ✓ | ✓ |
| Percent-encoded path | Block | ✓ | ✓ | ✓ | ✓ |
| Rule before any user-agent | Allow | ✓ | ✓ | ✓ | ✓ |
| Rule matching a query string | Block | ✓ | ✓ | ✓ | ✓ |
| Path in a different case | Allow | ✓ | ✓ | ✓ | ✓ |
/robots.txt itself | Allow | ✗ | ✗ | ✗ | ✓ |
What goes wrong
File order instead of longest match. urllib.robotparser and robotexclusionrulesparser apply the first rule that matches. With Disallow: /shop above Allow: /shop/sale, they block the sale pages the site opened up; with Allow: /shop above Disallow: /shop/checkout, they let the crawler into checkout pages the site closed. Our earlier guide to robots.txt and AI opt-out signals flagged the first case; the test shows it cuts both ways.
No wildcards in the standard library. urllib.robotparser treats * and $ as ordinary characters, so Disallow: /*.pdf blocks nothing. This is the most consequential gap: every wildcard rule in a file is silently ignored, and the crawler goes where it was asked not to. For our study of who blocks AI crawlers we had to write our own evaluator for this reason, after the built-in parser misread files such as Disallow: / followed by Allow: /$.
Groups not merged. When a file names the same bot in two places, both older parsers read only one of the groups, so rules in the other are lost.
Version numbers in the user-agent. robotspy did not match ExampleBot/1.0 against a group for ExampleBot. The RFC expects crawlers to match their product token, so pass the bare name, not a full User-Agent string, whatever parser you use.
robots.txt itself. Three parsers reported /robots.txt as blocked when a file disallows everything. That rarely matters in practice, since you fetch robots.txt before asking the parser anything, but it is a sign of how literally each one follows the standard.
Fetching robots.txt matters too
Parsing is half the job. RFC 9309 also says what to do when the file cannot be fetched: a 400 to 499 status means robots.txt is unavailable and the crawler “MAY access any resources on the server”; a server or network error means the crawler “MUST assume complete disallow”. It adds that crawlers “SHOULD NOT use the cached version for more than 24 hours”.
We checked how urllib.robotparser.read() handles status codes. It treated 404 as allow-all and 500 and 503 as disallow-all, as the RFC requires. It treated 401 and 403 as disallow-all, which is stricter than the RFC requires but errs on the safe side.
What to use
If you crawl with Scrapy, you already use Protego: it is Scrapy’s default ROBOTSTXT_PARSER. Elsewhere, it works on its own:
from protego import Protego
rules = Protego.parse(robots_txt)
if rules.can_fetch("https://example.com/shop/sale/shoes", "ExampleBot"):
... # allowed
If you are tied to urllib.robotparser, treat any file that uses *, $, overlapping Allow and Disallow rules or repeated user-agent groups as something it cannot read correctly, and handle those files another way.
Whatever you use, the rest of a responsible setup still applies: identify your crawler, keep request rates reasonable, cache robots.txt for no more than a day, and record what you collected and why, as our template for a company data collection policy describes. Proxies change where your requests come from, not what the site asked of you; teams using residential proxies for data collection should apply the same robots.txt rules whichever exit a request leaves from. Our guide to rotating residential proxies in Scrapy shows how the two fit together.
How we tested
On 29 November 2026 we wrote 20 test cases from the matching rules and examples in RFC 9309, sections 2.2.1 to 2.2.3, each a robots.txt file, a URL and the RFC’s expected answer for a crawler named ExampleBot. We ran every case through each parser’s own permission check in Python 3.11.10. For fetch behaviour, we served robots.txt from a local test server with status codes 200, 401, 403, 404, 500 and 503 and read it with urllib.robotparser.read(). Where the RFC says SHOULD rather than MUST, as for ties and case-sensitive paths, we counted the RFC’s preferred behaviour as correct.
The bottom line
Robots.txt is only as respected as it is parsed. Python’s built-in parser got 12 of our 20 RFC 9309 cases right, ignoring wildcards and reading rules in file order, which means it can crawl pages a site has blocked. Protego, Scrapy’s default, got all 20. Use a parser that follows the standard, pass your bot’s bare name, and treat a server error on robots.txt as a no.
Sources and references
- IETF, RFC 9309, Robots Exclusion Protocol (September 2022): rfc-editor.org
- Python documentation, urllib.robotparser: docs.python.org
- Protego: github.com
- Scrapy documentation, ROBOTSTXT_PARSER setting: docs.scrapy.org
- robotspy: pypi.org
- robotexclusionrulesparser: pypi.org