rest25/library/robotparser.rst => rest262/library/robotparser.rst
f1
2:mod:`robotparser` ---  Parser for robots.txt
3=============================================
4
5.. module:: robotparser
n6-   :synopsis: Loads a robots.txt file and answers questions about fetchability of other URLs.
n6+   :synopsis: Loads a robots.txt file and answers questions about
7+              fetchability of other URLs.
7-.. sectionauthor:: Skip Montanaro <skip@mojam.com>
8+.. sectionauthor:: Skip Montanaro <skip@pobox.com>
8
9
10.. index::
11   single: WWW
12   single: World Wide Web
13   single: URL
14   single: robots.txt
15
n17+.. 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.
22+ 
16This module provides a single class, :class:`RobotFileParser`, which answers
17questions about whether or not a particular user agent can fetch a URL on the
n18-Web site that published the :file:`robots.txt` file.  For more details on  the
n25+Web site that published the :file:`robots.txt` file.  For more details on the
19-structure of :file:`robots.txt` files, see
26+structure of :file:`robots.txt` files, see http://www.robotstxt.org/orig.html.
20-`<http://www.robotstxt.org/wc/norobots.html>`_.
21
22
23.. class:: RobotFileParser()
24
n25-   This class provides a set of methods to read, parse and answer questions about a
n31+   This class provides a set of methods to read, parse and answer questions
26-   single :file:`robots.txt` file.
32+   about a single :file:`robots.txt` file.
27
28
n29-   .. method:: RobotFileParser.set_url(url)
n35+   .. method:: set_url(url)
30
31      Sets the URL referring to a :file:`robots.txt` file.
32
33
n34-   .. method:: RobotFileParser.read()
n40+   .. method:: read()
35
36      Reads the :file:`robots.txt` URL and feeds it to the parser.
37
38
n39-   .. method:: RobotFileParser.parse(lines)
n45+   .. method:: parse(lines)
40
41      Parses the lines argument.
42
43
n44-   .. method:: RobotFileParser.can_fetch(useragent, url)
n50+   .. method:: can_fetch(useragent, url)
45
n46-      Returns ``True`` if the *useragent* is allowed to fetch the *url* according to
n52+      Returns ``True`` if the *useragent* is allowed to fetch the *url*
47-      the rules contained in the parsed :file:`robots.txt` file.
53+      according to the rules contained in the parsed :file:`robots.txt`
54+      file.
48
49
n50-   .. method:: RobotFileParser.mtime()
n57+   .. method:: mtime()
51
n52-      Returns the time the ``robots.txt`` file was last fetched.  This is useful for
n59+      Returns the time the ``robots.txt`` file was last fetched.  This is
53-      long-running web spiders that need to check for new ``robots.txt`` files
60+      useful for long-running web spiders that need to check for new
54-      periodically.
61+      ``robots.txt`` files periodically.
55
56
n57-   .. method:: RobotFileParser.modified()
n64+   .. method:: modified()
58
t59-      Sets the time the ``robots.txt`` file was last fetched to the current time.
t66+      Sets the time the ``robots.txt`` file was last fetched to the current
67+      time.
60
61The following example demonstrates basic use of the RobotFileParser class. ::
62
63   >>> import robotparser
64   >>> rp = robotparser.RobotFileParser()
65   >>> rp.set_url("http://www.musi-cal.com/robots.txt")
66   >>> rp.read()
67   >>> rp.can_fetch("*", "http://www.musi-cal.com/cgi-bin/search?city=San+Francisco")
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op