Common Atom Elements
====================
Atom feeds generally contain more information than :abbr:`RSS (Rich Site Summary)`
feeds (because more elements are required), but the most commonly used elements
are still title, link, subtitle/description, various dates, and ID.
This sample Atom feed is at `$READTHEDOCS_CANONICAL_URL/examples/atom10.xml
<$READTHEDOCS_CANONICAL_URL/examples/atom10.xml>`_.
.. sourcecode:: xml
Sample Feed
For documentation <em>only</em>
<p>Copyright 2005, Mark Pilgrim</p><
tag:feedparser.org,2005-11-09:/docs/examples/atom10.xml
Sample Toolkit
2005-11-09T11:56:34ZFirst entry titletag:feedparser.org,2005-11-09:/docs/examples/atom10.xml:32005-11-09T00:23:47Z2005-11-09T11:56:34ZWatch out for nasty tricks
Watch out for
nasty tricks
The feed elements are available in ``d.feed``.
Accessing Common Feed Elements
------------------------------
.. code-block:: pycon
>>> import feedparser
>>> d = feedparser.parse('$READTHEDOCS_CANONICAL_URL/examples/atom10.xml')
>>> d.feed.title
'Sample feed'
>>> d.feed.link
'http://example.org/'
>>> d.feed.subtitle
'For documentation only'
>>> d.feed.updated
'2005-11-09T11:56:34Z'
>>> d.feed.updated_parsed
(2005, 11, 9, 11, 56, 34, 2, 313, 0)
>>> d.feed.id
'tag:feedparser.org,2005-11-09:/docs/examples/atom10.xml'
Entries are available in ``d.entries``, which is a list. You access entries in
the order in which they appear in the original feed, so the first entry is
``d.entries[0]``.
Accessing Common Entry Elements
-------------------------------
.. code-block:: pycon
>>> import feedparser
>>> d = feedparser.parse('$READTHEDOCS_CANONICAL_URL/examples/atom10.xml')
>>> d.entries[0].title
'First entry title'
>>> d.entries[0].link
'http://example.org/entry/3
>>> d.entries[0].id
'tag:feedparser.org,2005-11-09:/docs/examples/atom10.xml:3'
>>> d.entries[0].published
'2005-11-09T00:23:47Z'
>>> d.entries[0].published_parsed
(2005, 11, 9, 0, 23, 47, 2, 313, 0)
>>> d.entries[0].updated
'2005-11-09T11:56:34Z'
>>> d.entries[0].updated_parsed
(2005, 11, 9, 11, 56, 34, 2, 313, 0)
>>> d.entries[0].summary
'Watch out for nasty tricks'
>>> d.entries[0].content
[{'type': 'application/xhtml+xml',
'base': 'http://example.org/entry/3',
'language': 'en-US',
'value': '
Watch out for nasty tricks
'}]
.. note::
The parsed summary and content are not the same as they appear in the
original feed. The original elements contained dangerous :abbr:`HTML
(HyperText Markup Language)` markup which was sanitized. See
:ref:`advanced.sanitization` for details.
Because Atom entries can have more than one content element,
``d.entries[0].content`` is a list of dictionaries. Each dictionary contains
metadata about a single content element. The two most important values in the
dictionary are the content type, in ``d.entries[0].content[0].type``, and the
actual content value, in ``d.entries[0].content[0].value``.
You can get this level of detail on other Atom elements too.