Common Atom Elements

Atom feeds generally contain more information than RSS feeds (because more elements are required), but the most commonly used elements are still title, link, tagline/summary, various dates, and ID.

This sample Atom feed is at http://feedparser.org/docs/examples/atom.xml.

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- several elements omitted in this example -->
<feed version="0.3"
      xmlns="http://purl.org/atom/ns#"
      xml:base="http://example.org/"
      xml:lang="en">
  <title type="text/plain" mode="escaped">Sample Feed</title>
  <tagline type="text/html" mode="escaped"
    For documentation &lt;em&gt;only&lt;/em&gt;
  </tagline>
  <link rel="alternate" type="text/html" href="/"/>
  <id>tag:feedparser.org,2004-04-20:/docs/examples/atom.xml</id>
  <modified>2004-04-20T11:56:34Z</modified>
  <entry>
    <title>First entry title</title>
    <link rel="alternate" type="text/html" href="/entry/3"/>
    <id>tag:feedparser.org,2004-04-20:/docs/examples/atom.xml:3</id>
    <created>2004-04-19T07:45:00Z</created>
    <issued>2004-04-20T00:23:47Z</issued>
    <modified>2004-04-20T11:56:34Z</modified>
    <summary type="text/plain" mode="escaped">Watch out for nasty tricks</summary>
    <content type="application/xhtml+xml" mode="xml"
             xml:base="http://example.org/entry/3" xml:lang="en-US">
      <div xmlns="http://www.w3.org/1999/xhtml">Watch out for
      <span style="background: url(javascript:window.location='http://example.org/')">
      nasty tricks</span></div>
    </content>
  </entry>
</feed>

feed elements are available in d.feed.

Example: Accessing Common Feed Elements

>>> import feedparser
>>> d = feedparser.parse('http://feedparser.org/docs/examples/atom.xml')
>>> d.feed.title
u'Sample feed'
>>> d.feed.link
u'http://example.org/'
>>> d.feed.tagline
u'For documentation <em>only</em>'
>>> d.feed.modified
2004-04-20T11:56:34Z
>>> d.feed.modified_parsed
(2004, 4, 20, 11, 56, 34, 1, 111, 0)
>>> d.feed.id
u'tag:feedparser.org,2004-04-20:/docs/examples/atom.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].

Example: Accessing Common Entry Elements

>>> import feedparser
>>> d = feedparser.parse('http://feedparser.org/docs/examples/atom.xml')
>>> d.entries[0].title
u'First entry title'
>>> d.entries[0].link
u'http://example.org/entry/3
>>> d.entries[0].id
u'tag:feedparser.org,2004-04-20:/docs/examples/atom.xml:3'
>>> d.entries[0].created
u'2004-04-19T07:45:00Z'
>>> d.entries[0].created_parsed
(2004, 4, 19, 7, 45, 0, 0, 110, 0)
>>> d.entries[0].issued
u'2004-04-20T00:23:47Z'
>>> d.entries[0].issued_parsed
(2004, 4, 20, 0, 23, 47, 1, 111, 0)
>>> d.entries[0].modified
u'2004-04-20T11:56:34Z'
>>> d.entries[0].modified_parsed
(2004, 4, 20, 11, 56, 34, 1, 111, 0)
>>> d.entries[0].summary
u'Watch out for nasty tricks'
>>> d.entries[0].content
[{'type': u'application/xhtml+xml',
 'mode': u'xml',
 'base': u'http://example.org/',
 'language': u'en',
 'value': u'<div>Watch out for <span>nasty tricks</span></div>'}]
Note
The parsed summary and content are not the same as they appear in the original feed. The original elements contained dangerous HTML markup which was sanitized. See HTML 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.

← Common RSS Elements
Getting Detailed Information on Atom Elements →