@@ -21,14 +21,17 @@ website that published the :file:`robots.txt` file. For more details on the
2121structure of :file: `robots.txt ` files, see :rfc: `9309 `.
2222
2323
24- .. class :: RobotFileParser(url ='')
24+ .. class :: RobotFileParser(url_or_request ='')
2525
2626 This class provides methods to read, parse and answer questions about the
27- :file: `robots.txt ` file at *url *.
27+ :file: `robots.txt ` file at *url * or a :class: `Request ` object with additional
28+ user-agent headers populated.
2829
29- .. method :: set_url(url)
3030
31- Sets the URL referring to a :file: `robots.txt ` file.
31+ .. method :: set_url(url_or_request)
32+
33+ Sets the URL referring to a :file: `robots.txt ` file or a :class: `Request `
34+ object with additional user-agent headers populated.
3235
3336 .. method :: read()
3437
@@ -102,3 +105,16 @@ class::
102105 True
103106 >>> rp.can_fetch("*", "http://www.pythontest.net/no-robots-here/")
104107 False
108+
109+
110+ The following example demonstrates use of a :class: `Request ` object with additional user-agent headers populated::
111+
112+ >>> import urllib.robotparser
113+ >>> import urllib.request
114+ >>> rp = urllib.robotparser.RobotFileParser()
115+ >>> rp.set_url(urllib.request.Request("http://en.wikipedia.org/robots.txt", headers={"User-Agent": "IsraBot"}))
116+ >>> rp.read()
117+ >>> rp.can_fetch("*", "https://en.wikipedia.org/")
118+ True
119+ >>> rp.can_fetch("*", "https://en.wikipedia.org/trap/")
120+ False
0 commit comments