← All notes

Python urllib.robotparser: parse robots.txt fetch rules

Answer: This module provides a single class, RobotFileParser, for robots.txt files.

Asking whether a fetch is allowed

The class answers whether a particular user agent can fetch a URL on the site that published the file.

set url stores the URL referring to a robots.txt file.

read fetches that URL and feeds it to the parser.

can fetch returns True if the useragent is allowed to fetch the URL.

Optional robots.txt parameters

crawl delay returns the Crawl-delay value for a useragent, or None when it is missing or invalid.

request rate returns the Request-rate parameter as a named tuple of requests and seconds.

site_maps returns Sitemap parameter contents as a list, or None when syntax is invalid.

mtime returns the time the robots.txt file was last fetched, which helps long-running spiders.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, urllib.robotparser — Parser for robots.txt; CPython, urllib.robotparser documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, urllib.robotparser — Parser for robots.txt; CPython, urllib.robotparser documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.

Cite this

Permanent ID: iil:note:r31smx1e

iinventedlight. 2026. "Python urllib.robotparser: parse robots.txt fetch rules." iinventedlight Library, iil:note:r31smx1e, version of 2026-11-24. https://iinventedlight.com/library/notes/python-urllib-robotparser/. License: CC-BY-4.0.

@misc{iil_note_r31smx1e,
  author = {{iinventedlight}},
  title = {{Python urllib.robotparser: parse robots.txt fetch rules}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-24},
  url = {https://iinventedlight.com/library/notes/python-urllib-robotparser/},
  note = {Permanent ID iil:note:r31smx1e. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-urllib-robotparser.md.