3
PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
6
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
8
<title>User-Agent and Referer Headers [Universal Feed Parser]</title>
9
<link rel="stylesheet" href="../css/feedparser.css" type="text/css">
10
<link rev="made" href="mailto:mark@diveintomark.org">
11
<meta name="generator" content="DocBook XSL Stylesheets V1.65.1">
12
<meta name="keywords" content="RSS, Atom, CDF, XML, feed, parser, Python">
13
<link rel="start" href="index.html" title="Documentation">
14
<link rel="up" href="http.html" title="HTTP Features">
15
<link rel="prev" href="http-etag.html" title="ETag and Last-Modified Headers">
16
<link rel="next" href="http-redirect.html" title="HTTP Redirects">
18
<body id="feedparser-org" class="docs">
19
<!--#include virtual="/inc/header.html"-->
22
<p id="breadcrumb">You are here: <a href="../">Home</a> → <a href="index.html">Documentation</a> → <a href="http.html">HTTP Features</a> → <span class="thispage">User-Agent and Referer Headers</span></p>
23
<div class="section" lang="en">
24
<div class="titlepage">
27
<h2 class="title"><a name="http.useragent" class="skip" href="#http.useragent" title="link to this section"><img src="images/permalink.gif" alt="[link]" title="link to this section" width="8" height="9"></a> User-Agent and Referer Headers
31
<div class="abstract">
32
<h3 class="title"></h3>
33
<p><span class="application">Universal Feed Parser</span> sends a default User-Agent string when it requests a feed from a web server.
40
<div class="informalexample">
41
<p>The default User-Agent string looks like this:</p><pre class="programlisting ">UniversalFeedParser/4.0 +http://feedparser.org/</pre></div>
42
<p>If you are embedding <span class="application">Universal Feed Parser</span> in a larger application, you should change the User-Agent to your application name and <acronym title="Uniform Resource Locator">URL</acronym>.
44
<div class="example"><a name="example.useragent" class="skip" href="#example.useragent" title="link to this example"><img src="images/permalink.gif" alt="[link]" title="link to this example" width="8" height="9"></a>
45
<h3 class="title">Example: Customizing the User-Agent</h3><pre class="screen"><tt class="prompt">>>> </tt><span class="userinput"><font color='navy'><b>import</b></font> feedparser</span>
4
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
<title>User-Agent and Referer Headers [Universal Feed Parser]</title>
6
<link rel="stylesheet" href="css/feedparser.css" type="text/css">
7
<link rev="made" href="mailto:mark@diveintomark.org">
8
<meta name="generator" content="DocBook XSL Stylesheets V1.65.1">
9
<meta name="keywords" content="RSS, Atom, CDF, XML, feed, parser, Python">
10
<link rel="start" href="index.html" title="Documentation">
11
<link rel="up" href="http.html" title="HTTP Features">
12
<link rel="prev" href="http-etag.html" title="ETag and Last-Modified Headers">
13
<link rel="next" href="http-redirect.html" title="HTTP Redirects">
15
<body id="feedparser-org" class="docs">
16
<div class="z" id="intro"><div class="sectionInner"><div class="sectionInner2">
17
<div class="s" id="pageHeader">
18
<h1><a href="/"><span>Universal Feed Parser</span></a></h1>
19
<p><span>Parse RSS and Atom feeds in Python. 3000 unit tests. Open source.</span></p>
21
<div class="s" id="quickSummary"><ul>
23
<a href="http://sourceforge.net/projects/feedparser/"><span>Download</span></a> ·</li>
25
<a href="http://feedparser.org/docs/"><span>Documentation</span></a> ·</li>
27
<a href="http://feedparser.org/tests/"><span>Unit tests</span></a> ·</li>
28
<li class="li4"><a href="http://sourceforge.net/tracker/?func=browse&group_id=112328&atid=661937"><span>Report a bug</span></a></li>
31
<div id="main"><div id="mainInner">
32
<p id="breadcrumb">You are here: <a href="index.html">Documentation</a> → <a href="http.html">HTTP Features</a> → <span class="thispage">User-Agent and Referer Headers</span></p>
33
<div class="section" lang="en">
34
<div class="titlepage">
36
<div><h2 class="title">
37
<a name="http.useragent" class="skip" href="#http.useragent" title="link to this section"><img src="images/permalink.gif" alt="[link]" title="link to this section" width="8" height="9"></a> User-Agent and Referer Headers</h2></div>
38
<div><div class="abstract">
39
<h3 class="title"></h3>
40
<p><span class="application">Universal Feed Parser</span> sends a default User-Agent string when it requests a feed from a web server.</p>
45
<div class="informalexample">
46
<p>The default User-Agent string looks like this:</p>
47
<pre class="programlisting ">UniversalFeedParser/4.1 +http://feedparser.org/</pre>
49
<p>If you are embedding <span class="application">Universal Feed Parser</span> in a larger application, you should change the User-Agent to your application name and <acronym title="Uniform Resource Locator">URL</acronym>.</p>
51
<a name="example.useragent" class="skip" href="#example.useragent" title="link to this example"><img src="images/permalink.gif" alt="[link]" title="link to this example" width="8" height="9"></a> <h3 class="title">Example: Customizing the User-Agent</h3>
52
<pre class="screen"><tt class="prompt">>>> </tt><span class="userinput"><font color='navy'><b>import</b></font> feedparser</span>
46
53
<tt class="prompt">>>> </tt><span class="userinput">d = feedparser.parse('<a href="http://feedparser.org/docs/examples/atom10.xml">http://feedparser.org/docs/examples/atom10.xml</a>', \</span>
47
<tt class="prompt">... </tt> <span class="userinput"> agent=<font color='olive'>'MyApp/1.0 +http://example.com/'</font>)</span></pre></div>
48
<p>You can also set the User-Agent once, globally, and then call the <tt class="function">parse</tt> function normally.
50
<div class="example"><a name="example.useragent.permanent" class="skip" href="#example.useragent.permanent" title="link to this example"><img src="images/permalink.gif" alt="[link]" title="link to this example" width="8" height="9"></a>
51
<h3 class="title">Example: Customizing the User-Agent permanently</h3><pre class="screen"><tt class="prompt">>>> </tt><span class="userinput"><font color='navy'><b>import</b></font> feedparser</span>
54
<tt class="prompt">... </tt> <span class="userinput"> agent=<font color='olive'>'MyApp/1.0 +http://example.com/'</font>)</span></pre>
56
<p>You can also set the User-Agent once, globally, and then call the <tt class="function">parse</tt> function normally.</p>
58
<a name="example.useragent.permanent" class="skip" href="#example.useragent.permanent" title="link to this example"><img src="images/permalink.gif" alt="[link]" title="link to this example" width="8" height="9"></a> <h3 class="title">Example: Customizing the User-Agent permanently</h3>
59
<pre class="screen"><tt class="prompt">>>> </tt><span class="userinput"><font color='navy'><b>import</b></font> feedparser</span>
52
60
<tt class="prompt">>>> </tt><span class="userinput">feedparser.USER_AGENT = <font color='olive'>"MyApp/1.0 +http://example.com/"</font></span>
53
<tt class="prompt">>>> </tt><span class="userinput">d = feedparser.parse('<a href="http://feedparser.org/docs/examples/atom10.xml">http://feedparser.org/docs/examples/atom10.xml</a>')</span></pre></div>
54
<p><span class="application">Universal Feed Parser</span> also lets you set the referrer when you download a feed from a web server. This is discouraged, because it is a violation
55
of <a 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.
57
<div class="example"><a name="example.referrer" class="skip" href="#example.referrer" title="link to this example"><img src="images/permalink.gif" alt="[link]" title="link to this example" width="8" height="9"></a>
58
<h3 class="title">Example: Customizing the referrer</h3><pre class="screen"><tt class="prompt">>>> </tt><span class="userinput"><font color='navy'><b>import</b></font> feedparser</span>
61
<tt class="prompt">>>> </tt><span class="userinput">d = feedparser.parse('<a href="http://feedparser.org/docs/examples/atom10.xml">http://feedparser.org/docs/examples/atom10.xml</a>')</span></pre>
63
<p><span class="application">Universal Feed Parser</span> 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 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>
65
<a name="example.referrer" class="skip" href="#example.referrer" title="link to this example"><img src="images/permalink.gif" alt="[link]" title="link to this example" width="8" height="9"></a> <h3 class="title">Example: Customizing the referrer</h3>
66
<pre class="screen"><tt class="prompt">>>> </tt><span class="userinput"><font color='navy'><b>import</b></font> feedparser</span>
59
67
<tt class="prompt">>>> </tt><span class="userinput">d = feedparser.parse('<a href="http://feedparser.org/docs/examples/atom10.xml">http://feedparser.org/docs/examples/atom10.xml</a>', \</span>
60
<tt class="prompt">... </tt> <span class="userinput">referrer=<font color='olive'>'http://example.com/'</font>)</span></pre></div>
62
<div style="float: left">← <a class="NavigationArrow" href="http-etag.html">ETag and Last-Modified Headers</a></div>
63
<div style="text-align: right"><a class="NavigationArrow" href="http-redirect.html">HTTP Redirects</a> →
65
<hr style="clear:both">
67
<p class="copyright">Copyright © 2004, 2005 Mark Pilgrim</p>
b'\\ No newline at end of file'
68
<tt class="prompt">... </tt> <span class="userinput">referrer=<font color='olive'>'http://example.com/'</font>)</span></pre>
71
<div style="float: left">← <a class="NavigationArrow" href="http-etag.html">ETag and Last-Modified Headers</a>
73
<div style="text-align: right">
74
<a class="NavigationArrow" href="http-redirect.html">HTTP Redirects</a> →</div>
75
<hr style="clear:both">
76
<div class="footer"><p class="copyright">Copyright © 2004, 2005, 2006 Mark Pilgrim</p></div>