File: http-useragent.rst

package info (click to toggle)
feedparser 6.0.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,540 kB
  • sloc: xml: 11,459; python: 4,575; makefile: 7
file content (57 lines) | stat: -rw-r--r-- 1,557 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
User-Agent and Referer Headers
==============================

:program:`Universal Feed Parser` sends a default User-Agent string when it
requests a feed from a web server.


The default User-Agent string looks like this:

::

    UniversalFeedParser/5.0.1 +http://feedparser.org/

If you are embedding :program:`Universal Feed Parser` in a larger application,
you should change the User-Agent to your application name and
:abbr:`URL (Uniform Resource Locator)`.


Customizing the User-Agent
--------------------------

::

    >>> import feedparser
    >>> d = feedparser.parse('http://feedparser.org/docs/examples/atom10.xml',
    agent='MyApp/1.0 +http://example.com/')

You can also set the User-Agent once, globally, and then call the ``parse``
function normally.


Customizing the User-Agent permanently
--------------------------------------

::

    >>> import feedparser
    >>> feedparser.USER_AGENT = "MyApp/1.0 +http://example.com/"
    >>> d = feedparser.parse('http://feedparser.org/docs/examples/atom10.xml')


:program:`Universal Feed Parser` also lets you set the referrer when you
download a feed from a web server.  This is discouraged, because it is a
violation of `RFC 2616 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.36>`_.
The default behavior is to send a blank referrer, and you should never need to
override this.


Customizing the referrer
------------------------

::

    >>> import feedparser
    >>> d = feedparser.parse('http://feedparser.org/docs/examples/atom10.xml',
    referrer='http://example.com/')