annotate Doc/lib/librobotparser.tex @ 24042:63fbbed10714 legacy-trunk

Simplify HTTPSConnection constructor. See discussion in SF bug 458463.
author Jeremy Hylton <jeremy@alum.mit.edu>
date Fri, 28 Jun 2002 23:38:14 +0000
parents 73d145bfd8e4
children bf00b56c14a9
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}
20907
316fffd80b16 Adjust the module synopsis to avoid margin overruns in the PDF format.
Fred Drake <fdrake@acm.org>
parents: 18574
diff changeset
5 \modulesynopsis{Loads a \protect\file{robots.txt} file and
316fffd80b16 Adjust the module synopsis to avoid margin overruns in the PDF format.
Fred Drake <fdrake@acm.org>
parents: 18574
diff changeset
6 answers questions about fetchability of other URLs.}
12198
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
7 \sectionauthor{Skip Montanaro}{skip@mojam.com}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
8
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
9 \index{WWW}
18574
346dcafc878b Minor changes to match the style guide.
Fred Drake <fdrake@acm.org>
parents: 12530
diff changeset
10 \index{World Wide Web}
12198
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
11 \index{URL}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
12 \index{robots.txt}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
13
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
14 This module provides a single class, \class{RobotFileParser}, which answers
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
15 questions about whether or not a particular user agent can fetch a URL on
18574
346dcafc878b Minor changes to match the style guide.
Fred Drake <fdrake@acm.org>
parents: 12530
diff changeset
16 the Web site that published the \file{robots.txt} file. For more details on
12198
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
17 the structure of \file{robots.txt} files, see
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
18 \url{http://info.webcrawler.com/mak/projects/robots/norobots.html}.
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
19
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
20 \begin{classdesc}{RobotFileParser}{}
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 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
23 about a single \file{robots.txt} file.
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
24
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
25 \begin{methoddesc}{set_url}{url}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
26 Sets the URL referring to a \file{robots.txt} file.
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
27 \end{methoddesc}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
28
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
29 \begin{methoddesc}{read}{}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
30 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
31 \end{methoddesc}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
32
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
33 \begin{methoddesc}{parse}{lines}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
34 Parses the lines argument.
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
35 \end{methoddesc}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
36
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
37 \begin{methoddesc}{can_fetch}{useragent, url}
22835
73d145bfd8e4 Update doc to reflect Tim's changes to bool.
Neal Norwitz <nnorwitz@gmail.com>
parents: 20907
diff changeset
38 Returns \code{True} if the \var{useragent} is allowed to fetch the \var{url}
12198
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
39 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
40 \end{methoddesc}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
41
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
42 \begin{methoddesc}{mtime}{}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
43 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
44 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
45 \code{robots.txt} files periodically.
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
46 \end{methoddesc}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
47
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
48 \begin{methoddesc}{modified}{}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
49 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
50 time.
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
51 \end{methoddesc}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
52
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
53 \end{classdesc}
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 The following example demonstrates basic use of the RobotFileParser class.
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 \begin{verbatim}
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
58 >>> import robotparser
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
59 >>> rp = robotparser.RobotFileParser()
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
60 >>> rp.set_url("http://www.musi-cal.com/robots.txt")
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
61 >>> rp.read()
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
62 >>> rp.can_fetch("*", "http://www.musi-cal.com/cgi-bin/search?city=San+Francisco")
22835
73d145bfd8e4 Update doc to reflect Tim's changes to bool.
Neal Norwitz <nnorwitz@gmail.com>
parents: 20907
diff changeset
63 False
12198
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
64 >>> rp.can_fetch("*", "http://www.musi-cal.com/")
22835
73d145bfd8e4 Update doc to reflect Tim's changes to bool.
Neal Norwitz <nnorwitz@gmail.com>
parents: 20907
diff changeset
65 True
12198
4763a3d59ab9 Two new sections. Preliminary.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
66 \end{verbatim}