Networking and Internet Modules

urllib.robotparser

Parses robots.txt rules and answers whether a user agent may fetch a URL according to those rules. The parser can consume local lines without downloading anything. Robots rules are crawler guidance, not access control or permission to bypass other restrictions.

Formal Syntax & Structure

python syntaxpython
import urllib.robotparser

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
from urllib.robotparser import RobotFileParserrules = RobotFileParser()rules.parse(["User-agent: *", "Disallow: /private/"])print(rules.can_fetch("StudyBot", "https://example.invalid/private/a"))
Python Reference