~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to python-2.7.12-docs-html/library/robotparser.html

  • Committer: Dave Kuhlman
  • Date: 2017-04-15 16:24:56 UTC
  • Revision ID: dkuhlman@davekuhlman.org-20170415162456-iav9vozzg4iwqwv3
Updated docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
2
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
3
 
 
4
 
 
5
<html xmlns="http://www.w3.org/1999/xhtml">
 
6
  <head>
 
7
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
8
    
 
9
    <title>13.3. robotparser — Parser for robots.txt &mdash; Python 2.7.12 documentation</title>
 
10
    
 
11
    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
 
12
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
 
13
    
 
14
    <script type="text/javascript">
 
15
      var DOCUMENTATION_OPTIONS = {
 
16
        URL_ROOT:    '../',
 
17
        VERSION:     '2.7.12',
 
18
        COLLAPSE_INDEX: false,
 
19
        FILE_SUFFIX: '.html',
 
20
        HAS_SOURCE:  true
 
21
      };
 
22
    </script>
 
23
    <script type="text/javascript" src="../_static/jquery.js"></script>
 
24
    <script type="text/javascript" src="../_static/underscore.js"></script>
 
25
    <script type="text/javascript" src="../_static/doctools.js"></script>
 
26
    <script type="text/javascript" src="../_static/sidebar.js"></script>
 
27
    <link rel="search" type="application/opensearchdescription+xml"
 
28
          title="Search within Python 2.7.12 documentation"
 
29
          href="../_static/opensearch.xml"/>
 
30
    <link rel="author" title="About these documents" href="../about.html" />
 
31
    <link rel="copyright" title="Copyright" href="../copyright.html" />
 
32
    <link rel="top" title="Python 2.7.12 documentation" href="../contents.html" />
 
33
    <link rel="up" title="13. File Formats" href="fileformats.html" />
 
34
    <link rel="next" title="13.4. netrc — netrc file processing" href="netrc.html" />
 
35
    <link rel="prev" title="13.2. ConfigParser — Configuration file parser" href="configparser.html" />
 
36
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 
37
    <script type="text/javascript" src="../_static/copybutton.js"></script>
 
38
    <script type="text/javascript" src="../_static/version_switch.js"></script>
 
39
 
 
40
    
 
41
 
 
42
  </head>
 
43
  <body role="document">  
 
44
    <div class="related" role="navigation" aria-label="related navigation">
 
45
      <h3>Navigation</h3>
 
46
      <ul>
 
47
        <li class="right" style="margin-right: 10px">
 
48
          <a href="../genindex.html" title="General Index"
 
49
             accesskey="I">index</a></li>
 
50
        <li class="right" >
 
51
          <a href="../py-modindex.html" title="Python Module Index"
 
52
             >modules</a> |</li>
 
53
        <li class="right" >
 
54
          <a href="netrc.html" title="13.4. netrc — netrc file processing"
 
55
             accesskey="N">next</a> |</li>
 
56
        <li class="right" >
 
57
          <a href="configparser.html" title="13.2. ConfigParser — Configuration file parser"
 
58
             accesskey="P">previous</a> |</li>
 
59
        <li><img src="../_static/py.png" alt=""
 
60
                 style="vertical-align: middle; margin-top: -1px"/></li>
 
61
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
 
62
        <li>
 
63
          <span class="version_switcher_placeholder">2.7.12</span>
 
64
          <a href="../index.html">Documentation</a> &raquo;
 
65
        </li>
 
66
 
 
67
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
 
68
          <li class="nav-item nav-item-2"><a href="fileformats.html" accesskey="U">13. File Formats</a> &raquo;</li> 
 
69
      </ul>
 
70
    </div>    
 
71
 
 
72
    <div class="document">
 
73
      <div class="documentwrapper">
 
74
        <div class="bodywrapper">
 
75
          <div class="body" role="main">
 
76
            
 
77
  <div class="section" id="module-robotparser">
 
78
<span id="robotparser-parser-for-robots-txt"></span><h1>13.3. <a class="reference internal" href="#module-robotparser" title="robotparser: Loads a robots.txt file and answers questions about fetchability of other URLs."><code class="xref py py-mod docutils literal"><span class="pre">robotparser</span></code></a> &#8212;  Parser for robots.txt<a class="headerlink" href="#module-robotparser" title="Permalink to this headline">¶</a></h1>
 
79
<div class="admonition note" id="index-0">
 
80
<p class="first admonition-title">Note</p>
 
81
<p class="last">The <a class="reference internal" href="#module-robotparser" title="robotparser: Loads a robots.txt file and answers questions about fetchability of other URLs."><code class="xref py py-mod docutils literal"><span class="pre">robotparser</span></code></a> module has been renamed <code class="xref py py-mod docutils literal"><span class="pre">urllib.robotparser</span></code> in
 
82
Python 3.
 
83
The <a class="reference internal" href="../glossary.html#term-2to3"><span class="xref std std-term">2to3</span></a> tool will automatically adapt imports when converting
 
84
your sources to Python 3.</p>
 
85
</div>
 
86
<p>This module provides a single class, <a class="reference internal" href="#robotparser.RobotFileParser" title="robotparser.RobotFileParser"><code class="xref py py-class docutils literal"><span class="pre">RobotFileParser</span></code></a>, which answers
 
87
questions about whether or not a particular user agent can fetch a URL on the
 
88
Web site that published the <code class="file docutils literal"><span class="pre">robots.txt</span></code> file.  For more details on the
 
89
structure of <code class="file docutils literal"><span class="pre">robots.txt</span></code> files, see <a class="reference external" href="http://www.robotstxt.org/orig.html">http://www.robotstxt.org/orig.html</a>.</p>
 
90
<dl class="class">
 
91
<dt id="robotparser.RobotFileParser">
 
92
<em class="property">class </em><code class="descclassname">robotparser.</code><code class="descname">RobotFileParser</code><span class="sig-paren">(</span><em>url=''</em><span class="sig-paren">)</span><a class="headerlink" href="#robotparser.RobotFileParser" title="Permalink to this definition">¶</a></dt>
 
93
<dd><p>This class provides methods to read, parse and answer questions about the
 
94
<code class="file docutils literal"><span class="pre">robots.txt</span></code> file at <em>url</em>.</p>
 
95
<dl class="method">
 
96
<dt id="robotparser.RobotFileParser.set_url">
 
97
<code class="descname">set_url</code><span class="sig-paren">(</span><em>url</em><span class="sig-paren">)</span><a class="headerlink" href="#robotparser.RobotFileParser.set_url" title="Permalink to this definition">¶</a></dt>
 
98
<dd><p>Sets the URL referring to a <code class="file docutils literal"><span class="pre">robots.txt</span></code> file.</p>
 
99
</dd></dl>
 
100
 
 
101
<dl class="method">
 
102
<dt id="robotparser.RobotFileParser.read">
 
103
<code class="descname">read</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#robotparser.RobotFileParser.read" title="Permalink to this definition">¶</a></dt>
 
104
<dd><p>Reads the <code class="file docutils literal"><span class="pre">robots.txt</span></code> URL and feeds it to the parser.</p>
 
105
</dd></dl>
 
106
 
 
107
<dl class="method">
 
108
<dt id="robotparser.RobotFileParser.parse">
 
109
<code class="descname">parse</code><span class="sig-paren">(</span><em>lines</em><span class="sig-paren">)</span><a class="headerlink" href="#robotparser.RobotFileParser.parse" title="Permalink to this definition">¶</a></dt>
 
110
<dd><p>Parses the lines argument.</p>
 
111
</dd></dl>
 
112
 
 
113
<dl class="method">
 
114
<dt id="robotparser.RobotFileParser.can_fetch">
 
115
<code class="descname">can_fetch</code><span class="sig-paren">(</span><em>useragent</em>, <em>url</em><span class="sig-paren">)</span><a class="headerlink" href="#robotparser.RobotFileParser.can_fetch" title="Permalink to this definition">¶</a></dt>
 
116
<dd><p>Returns <code class="docutils literal"><span class="pre">True</span></code> if the <em>useragent</em> is allowed to fetch the <em>url</em>
 
117
according to the rules contained in the parsed <code class="file docutils literal"><span class="pre">robots.txt</span></code>
 
118
file.</p>
 
119
</dd></dl>
 
120
 
 
121
<dl class="method">
 
122
<dt id="robotparser.RobotFileParser.mtime">
 
123
<code class="descname">mtime</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#robotparser.RobotFileParser.mtime" title="Permalink to this definition">¶</a></dt>
 
124
<dd><p>Returns the time the <code class="docutils literal"><span class="pre">robots.txt</span></code> file was last fetched.  This is
 
125
useful for long-running web spiders that need to check for new
 
126
<code class="docutils literal"><span class="pre">robots.txt</span></code> files periodically.</p>
 
127
</dd></dl>
 
128
 
 
129
<dl class="method">
 
130
<dt id="robotparser.RobotFileParser.modified">
 
131
<code class="descname">modified</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#robotparser.RobotFileParser.modified" title="Permalink to this definition">¶</a></dt>
 
132
<dd><p>Sets the time the <code class="docutils literal"><span class="pre">robots.txt</span></code> file was last fetched to the current
 
133
time.</p>
 
134
</dd></dl>
 
135
 
 
136
</dd></dl>
 
137
 
 
138
<p>The following example demonstrates basic use of the RobotFileParser class.</p>
 
139
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">robotparser</span>
 
140
<span class="gp">&gt;&gt;&gt; </span><span class="n">rp</span> <span class="o">=</span> <span class="n">robotparser</span><span class="o">.</span><span class="n">RobotFileParser</span><span class="p">()</span>
 
141
<span class="gp">&gt;&gt;&gt; </span><span class="n">rp</span><span class="o">.</span><span class="n">set_url</span><span class="p">(</span><span class="s2">&quot;http://www.musi-cal.com/robots.txt&quot;</span><span class="p">)</span>
 
142
<span class="gp">&gt;&gt;&gt; </span><span class="n">rp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
 
143
<span class="gp">&gt;&gt;&gt; </span><span class="n">rp</span><span class="o">.</span><span class="n">can_fetch</span><span class="p">(</span><span class="s2">&quot;*&quot;</span><span class="p">,</span> <span class="s2">&quot;http://www.musi-cal.com/cgi-bin/search?city=San+Francisco&quot;</span><span class="p">)</span>
 
144
<span class="go">False</span>
 
145
<span class="gp">&gt;&gt;&gt; </span><span class="n">rp</span><span class="o">.</span><span class="n">can_fetch</span><span class="p">(</span><span class="s2">&quot;*&quot;</span><span class="p">,</span> <span class="s2">&quot;http://www.musi-cal.com/&quot;</span><span class="p">)</span>
 
146
<span class="go">True</span>
 
147
</pre></div>
 
148
</div>
 
149
</div>
 
150
 
 
151
 
 
152
          </div>
 
153
        </div>
 
154
      </div>
 
155
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
 
156
        <div class="sphinxsidebarwrapper">
 
157
  <h4>Previous topic</h4>
 
158
  <p class="topless"><a href="configparser.html"
 
159
                        title="previous chapter">13.2. <code class="docutils literal"><span class="pre">ConfigParser</span></code> &#8212; Configuration file parser</a></p>
 
160
  <h4>Next topic</h4>
 
161
  <p class="topless"><a href="netrc.html"
 
162
                        title="next chapter">13.4. <code class="docutils literal"><span class="pre">netrc</span></code> &#8212; netrc file processing</a></p>
 
163
<h3>This Page</h3>
 
164
<ul class="this-page-menu">
 
165
  <li><a href="../bugs.html">Report a Bug</a></li>
 
166
  <li><a href="../_sources/library/robotparser.txt"
 
167
         rel="nofollow">Show Source</a></li>
 
168
</ul>
 
169
 
 
170
<div id="searchbox" style="display: none" role="search">
 
171
  <h3>Quick search</h3>
 
172
    <form class="search" action="../search.html" method="get">
 
173
      <input type="text" name="q" />
 
174
      <input type="submit" value="Go" />
 
175
      <input type="hidden" name="check_keywords" value="yes" />
 
176
      <input type="hidden" name="area" value="default" />
 
177
    </form>
 
178
    <p class="searchtip" style="font-size: 90%">
 
179
    Enter search terms or a module, class or function name.
 
180
    </p>
 
181
</div>
 
182
<script type="text/javascript">$('#searchbox').show(0);</script>
 
183
        </div>
 
184
      </div>
 
185
      <div class="clearer"></div>
 
186
    </div>  
 
187
    <div class="related" role="navigation" aria-label="related navigation">
 
188
      <h3>Navigation</h3>
 
189
      <ul>
 
190
        <li class="right" style="margin-right: 10px">
 
191
          <a href="../genindex.html" title="General Index"
 
192
             >index</a></li>
 
193
        <li class="right" >
 
194
          <a href="../py-modindex.html" title="Python Module Index"
 
195
             >modules</a> |</li>
 
196
        <li class="right" >
 
197
          <a href="netrc.html" title="13.4. netrc — netrc file processing"
 
198
             >next</a> |</li>
 
199
        <li class="right" >
 
200
          <a href="configparser.html" title="13.2. ConfigParser — Configuration file parser"
 
201
             >previous</a> |</li>
 
202
        <li><img src="../_static/py.png" alt=""
 
203
                 style="vertical-align: middle; margin-top: -1px"/></li>
 
204
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
 
205
        <li>
 
206
          <span class="version_switcher_placeholder">2.7.12</span>
 
207
          <a href="../index.html">Documentation</a> &raquo;
 
208
        </li>
 
209
 
 
210
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
 
211
          <li class="nav-item nav-item-2"><a href="fileformats.html" >13. File Formats</a> &raquo;</li> 
 
212
      </ul>
 
213
    </div>  
 
214
    <div class="footer">
 
215
    &copy; <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
 
216
    <br />
 
217
    The Python Software Foundation is a non-profit corporation.
 
218
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
 
219
    <br />
 
220
    Last updated on Sep 20, 2016.
 
221
    <a href="../bugs.html">Found a bug</a>?
 
222
    <br />
 
223
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
 
224
    </div>
 
225
 
 
226
  </body>
 
227
</html>
 
 
b'\\ No newline at end of file'