Issue 2188: Documentation hint about disabling proxy detection.
[python.git] / Doc / library / robotparser.rst
blob6cc7df898ee0f2d296562be394b9483361915061
2 :mod:`robotparser` ---  Parser for robots.txt
3 =============================================
5 .. module:: robotparser
6    :synopsis: Loads a robots.txt file and answers questions about fetchability of other URLs.
7 .. sectionauthor:: Skip Montanaro <skip@pobox.com>
10 .. index::
11    single: WWW
12    single: World Wide Web
13    single: URL
14    single: robots.txt
16 This module provides a single class, :class:`RobotFileParser`, which answers
17 questions about whether or not a particular user agent can fetch a URL on the
18 Web site that published the :file:`robots.txt` file.  For more details on the
19 structure of :file:`robots.txt` files, see http://www.robotstxt.org/orig.html.
22 .. class:: RobotFileParser()
24    This class provides a set of methods to read, parse and answer questions about a
25    single :file:`robots.txt` file.
28    .. method:: RobotFileParser.set_url(url)
30       Sets the URL referring to a :file:`robots.txt` file.
33    .. method:: RobotFileParser.read()
35       Reads the :file:`robots.txt` URL and feeds it to the parser.
38    .. method:: RobotFileParser.parse(lines)
40       Parses the lines argument.
43    .. method:: RobotFileParser.can_fetch(useragent, url)
45       Returns ``True`` if the *useragent* is allowed to fetch the *url* according to
46       the rules contained in the parsed :file:`robots.txt` file.
49    .. method:: RobotFileParser.mtime()
51       Returns the time the ``robots.txt`` file was last fetched.  This is useful for
52       long-running web spiders that need to check for new ``robots.txt`` files
53       periodically.
56    .. method:: RobotFileParser.modified()
58       Sets the time the ``robots.txt`` file was last fetched to the current time.
60 The following example demonstrates basic use of the RobotFileParser class. ::
62    >>> import robotparser
63    >>> rp = robotparser.RobotFileParser()
64    >>> rp.set_url("http://www.musi-cal.com/robots.txt")
65    >>> rp.read()
66    >>> rp.can_fetch("*", "http://www.musi-cal.com/cgi-bin/search?city=San+Francisco")
67    False
68    >>> rp.can_fetch("*", "http://www.musi-cal.com/")
69    True