annotate Doc/lib/librobotparser.tex @ 16413:8819867f14ef legacy-trunk

Patch derived from Trent's 101162: a Python/C API testing framework. STILL NEEDS UNIX BUILD CHANGES.
author Tim Peters <tim.peters@gmail.com>
date Fri, 02 Feb 2001 05:57:15 +0000
parents c2bb5e4b04a8
children 346dcafc878b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12198
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1 \section{\module{robotparser} ---
12530
c2bb5e4b04a8 \file and \filenq should not be used in section titles; they are not
Fred Drake <fdrake@acm.org>
parents: 12198
diff changeset
2 Parser for robots.txt}
12198
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
3
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
4 \declaremodule{standard}{robotparser}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
5 \modulesynopsis{Accepts as input a list of lines or URL that refers to a
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
6 robots.txt file, parses the file, then builds a
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
7 set of rules from that list and answers questions
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
8 about fetchability of other URLs.}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
9 \sectionauthor{Skip Montanaro}{skip@mojam.com}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
10
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
11 \index{WWW}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
12 \index{World-Wide Web}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
13 \index{URL}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
14 \index{robots.txt}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
15
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
16 This module provides a single class, \class{RobotFileParser}, which answers
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
17 questions about whether or not a particular user agent can fetch a URL on
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
18 the web site that published the \file{robots.txt} file. For more details on
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
19 the structure of \file{robots.txt} files, see
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
20 \url{http://info.webcrawler.com/mak/projects/robots/norobots.html}.
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
21
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
22 \begin{classdesc}{RobotFileParser}{}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
23
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
24 This class provides a set of methods to read, parse and answer questions
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
25 about a single \file{robots.txt} file.
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
26
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
27 \begin{methoddesc}{set_url}{url}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
28 Sets the URL referring to a \file{robots.txt} file.
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
29 \end{methoddesc}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
30
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
31 \begin{methoddesc}{read}{}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
32 Reads the \file{robots.txt} URL and feeds it to the parser.
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
33 \end{methoddesc}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
34
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
35 \begin{methoddesc}{parse}{lines}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
36 Parses the lines argument.
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
37 \end{methoddesc}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
38
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
39 \begin{methoddesc}{can_fetch}{useragent, url}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
40 Returns true if the \var{useragent} is allowed to fetch the \var{url}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
41 according to the rules contained in the parsed \file{robots.txt} file.
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
42 \end{methoddesc}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
43
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
44 \begin{methoddesc}{mtime}{}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
45 Returns the time the \code{robots.txt} file was last fetched. This is
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
46 useful for long-running web spiders that need to check for new
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
47 \code{robots.txt} files periodically.
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
48 \end{methoddesc}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
49
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
50 \begin{methoddesc}{modified}{}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
51 Sets the time the \code{robots.txt} file was last fetched to the current
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
52 time.
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
53 \end{methoddesc}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
54
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
55 \end{classdesc}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
56
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
57 The following example demonstrates basic use of the RobotFileParser class.
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
58
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
59 \begin{verbatim}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
60 >>> import robotparser
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
61 >>> rp = robotparser.RobotFileParser()
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
62 >>> rp.set_url("http://www.musi-cal.com/robots.txt")
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
63 >>> rp.read()
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
64 >>> rp.can_fetch("*", "http://www.musi-cal.com/cgi-bin/search?city=San+Francisco")
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
65 0
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
66 >>> rp.can_fetch("*", "http://www.musi-cal.com/")
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
67 1
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
68 \end{verbatim}