Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > 7e03e96dde1cbbdbc7cc96424cd9e059 > files > 310

python-feedparser-doc-5.1.3-3.fc18.noarch.rpm



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>User-Agent and Referer Headers &mdash; feedparser 5.1.3 documentation</title>
    
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="_static/feedparser.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '5.1.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="feedparser 5.1.3 documentation" href="index.html" />
    <link rel="up" title="HTTP Features" href="http.html" />
    <link rel="next" title="HTTP Redirects" href="http-redirect.html" />
    <link rel="prev" title="ETag and Last-Modified Headers" href="http-etag.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="http-redirect.html" title="HTTP Redirects"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="http-etag.html" title="ETag and Last-Modified Headers"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">feedparser 5.1.3 documentation</a> &raquo;</li>
          <li><a href="http.html" accesskey="U"><abbr title="Hypertext Transfer Protocol">HTTP</abbr> Features</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="user-agent-and-referer-headers">
<h1>User-Agent and Referer Headers<a class="headerlink" href="#user-agent-and-referer-headers" title="Permalink to this headline">¶</a></h1>
<p><strong class="program">Universal Feed Parser</strong> sends a default User-Agent string when it
requests a feed from a web server.</p>
<p>The default User-Agent string looks like this:</p>
<div class="highlight-python"><pre>UniversalFeedParser/5.0.1 +http://feedparser.org/</pre>
</div>
<p>If you are embedding <strong class="program">Universal Feed Parser</strong> in a larger application,
you should change the User-Agent to your application name and
<abbr title="Uniform Resource Locator">URL</abbr>.</p>
<div class="section" id="customizing-the-user-agent">
<h2>Customizing the User-Agent<a class="headerlink" href="#customizing-the-user-agent" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">feedparser</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">feedparser</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="s">&#39;http://feedparser.org/docs/examples/atom10.xml&#39;</span><span class="p">,</span>
<span class="go">agent=&#39;MyApp/1.0 +http://example.com/&#39;)</span>
</pre></div>
</div>
<p>You can also set the User-Agent once, globally, and then call the <tt class="docutils literal"><span class="pre">parse</span></tt>
function normally.</p>
</div>
<div class="section" id="customizing-the-user-agent-permanently">
<h2>Customizing the User-Agent permanently<a class="headerlink" href="#customizing-the-user-agent-permanently" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">feedparser</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">feedparser</span><span class="o">.</span><span class="n">USER_AGENT</span> <span class="o">=</span> <span class="s">&quot;MyApp/1.0 +http://example.com/&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">feedparser</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="s">&#39;http://feedparser.org/docs/examples/atom10.xml&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p><strong class="program">Universal Feed Parser</strong> also lets you set the referrer when you
download a feed from a web server.  This is discouraged, because it is a
violation of <a class="reference external" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.36">RFC 2616</a>.
The default behavior is to send a blank referrer, and you should never need to
override this.</p>
</div>
<div class="section" id="customizing-the-referrer">
<h2>Customizing the referrer<a class="headerlink" href="#customizing-the-referrer" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">feedparser</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="n">feedparser</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="s">&#39;http://feedparser.org/docs/examples/atom10.xml&#39;</span><span class="p">,</span>
<span class="go">referrer=&#39;http://example.com/&#39;)</span>
</pre></div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">User-Agent and Referer Headers</a><ul>
<li><a class="reference internal" href="#customizing-the-user-agent">Customizing the User-Agent</a></li>
<li><a class="reference internal" href="#customizing-the-user-agent-permanently">Customizing the User-Agent permanently</a></li>
<li><a class="reference internal" href="#customizing-the-referrer">Customizing the referrer</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="http-etag.html"
                        title="previous chapter">ETag and Last-Modified Headers</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="http-redirect.html"
                        title="next chapter"><abbr title="Hypertext Transfer Protocol">HTTP</abbr> Redirects</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/http-useragent.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="http-redirect.html" title="HTTP Redirects"
             >next</a> |</li>
        <li class="right" >
          <a href="http-etag.html" title="ETag and Last-Modified Headers"
             >previous</a> |</li>
        <li><a href="index.html">feedparser 5.1.3 documentation</a> &raquo;</li>
          <li><a href="http.html" ><abbr title="Hypertext Transfer Protocol">HTTP</abbr> Features</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2004-2008 Mark Pilgrim, 2010-2012 Kurt McKee.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>