Issue #7117, continued: Change round implementation to use the correctly-rounded
[python.git] / Doc / library / robotparser.rst
blobba7e557873beeb6d7d11397410f2878cbb212f08
2 :mod:`robotparser` ---  Parser for robots.txt
3 =============================================
5 .. module:: robotparser
6    :synopsis: Loads a robots.txt file and answers questions about
7               fetchability of other URLs.
8 .. sectionauthor:: Skip Montanaro <skip@pobox.com>
11 .. index::
12    single: WWW
13    single: World Wide Web
14    single: URL
15    single: robots.txt
17 .. note::
18    The :mod:`robotparser` module has been renamed :mod:`urllib.robotparser` in
19    Python 3.0.
20    The :term:`2to3` tool will automatically adapt imports when converting
21    your sources to 3.0.
23 This module provides a single class, :class:`RobotFileParser`, which answers
24 questions about whether or not a particular user agent can fetch a URL on the
25 Web site that published the :file:`robots.txt` file.  For more details on the
26 structure of :file:`robots.txt` files, see http://www.robotstxt.org/orig.html.
29 .. class:: RobotFileParser()
31    This class provides a set of methods to read, parse and answer questions
32    about a single :file:`robots.txt` file.
35    .. method:: set_url(url)
37       Sets the URL referring to a :file:`robots.txt` file.
40    .. method:: read()
42       Reads the :file:`robots.txt` URL and feeds it to the parser.
45    .. method:: parse(lines)
47       Parses the lines argument.
50    .. method:: can_fetch(useragent, url)
52       Returns ``True`` if the *useragent* is allowed to fetch the *url*
53       according to the rules contained in the parsed :file:`robots.txt`
54       file.
57    .. method:: mtime()
59       Returns the time the ``robots.txt`` file was last fetched.  This is
60       useful for long-running web spiders that need to check for new
61       ``robots.txt`` files periodically.
64    .. method:: modified()
66       Sets the time the ``robots.txt`` file was last fetched to the current
67       time.
69 The following example demonstrates basic use of the RobotFileParser class. ::
71    >>> import robotparser
72    >>> rp = robotparser.RobotFileParser()
73    >>> rp.set_url("http://www.musi-cal.com/robots.txt")
74    >>> rp.read()
75    >>> rp.can_fetch("*", "http://www.musi-cal.com/cgi-bin/search?city=San+Francisco")
76    False
77    >>> rp.can_fetch("*", "http://www.musi-cal.com/")
78    True