Sophie

Sophie

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

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>Common Atom Elements &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="Basic Features" href="basic.html" />
    <link rel="next" title="Getting Detailed Information on Atom Elements" href="atom-detail.html" />
    <link rel="prev" title="Common RSS Elements" href="common-rss-elements.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="atom-detail.html" title="Getting Detailed Information on Atom Elements"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="common-rss-elements.html" title="Common RSS Elements"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">feedparser 5.1.3 documentation</a> &raquo;</li>
          <li><a href="basic.html" accesskey="U">Basic Features</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="common-atom-elements">
<h1>Common Atom Elements<a class="headerlink" href="#common-atom-elements" title="Permalink to this headline">¶</a></h1>
<p>Atom feeds generally contain more information than <abbr title="Rich Site Summary">RSS</abbr>
feeds (because more elements are required), but the most commonly used elements
are still title, link, subtitle/description, various dates, and ID.</p>
<p>This sample Atom feed is at <a class="reference external" href="http://feedparser.org/docs/examples/atom10.xml">http://feedparser.org/docs/examples/atom10.xml</a>.</p>
<div class="highlight-xml"><div class="highlight"><pre><span class="cp">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span>
<span class="nt">&lt;feed</span> <span class="na">xmlns=</span><span class="s">&quot;http://www.w3.org/2005/Atom&quot;</span>
<span class="na">xml:base=</span><span class="s">&quot;http://example.org/&quot;</span>
<span class="na">xml:lang=</span><span class="s">&quot;en&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;title</span> <span class="na">type=</span><span class="s">&quot;text&quot;</span><span class="nt">&gt;</span>Sample Feed<span class="nt">&lt;/title&gt;</span>
<span class="nt">&lt;subtitle</span> <span class="na">type=</span><span class="s">&quot;html&quot;</span><span class="nt">&gt;</span>
For documentation <span class="ni">&amp;lt;</span>em<span class="ni">&amp;gt;</span>only<span class="ni">&amp;lt;</span>/em<span class="ni">&amp;gt;</span>
<span class="nt">&lt;/subtitle&gt;</span>
<span class="nt">&lt;link</span> <span class="na">rel=</span><span class="s">&quot;alternate&quot;</span> <span class="na">href=</span><span class="s">&quot;/&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;link</span> <span class="na">rel=</span><span class="s">&quot;self&quot;</span>
<span class="na">type=</span><span class="s">&quot;application/atom+xml&quot;</span>
<span class="na">href=</span><span class="s">&quot;http://www.example.org/atom10.xml&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;rights</span> <span class="na">type=</span><span class="s">&quot;html&quot;</span><span class="nt">&gt;</span>
<span class="ni">&amp;lt;</span>p&gt;Copyright 2005, Mark Pilgrim<span class="ni">&amp;lt;</span>/p&gt;<span class="ni">&amp;lt;</span>
<span class="nt">&lt;/rights&gt;</span>
<span class="nt">&lt;id&gt;</span>tag:feedparser.org,2005-11-09:/docs/examples/atom10.xml<span class="nt">&lt;/id&gt;</span>
<span class="nt">&lt;generator</span>
<span class="na">uri=</span><span class="s">&quot;http://example.org/generator/&quot;</span>
<span class="na">version=</span><span class="s">&quot;4.0&quot;</span><span class="nt">&gt;</span>
Sample Toolkit
<span class="nt">&lt;/generator&gt;</span>
<span class="nt">&lt;updated&gt;</span>2005-11-09T11:56:34Z<span class="nt">&lt;/updated&gt;</span>
<span class="nt">&lt;entry&gt;</span>
<span class="nt">&lt;title&gt;</span>First entry title<span class="nt">&lt;/title&gt;</span>
<span class="nt">&lt;link</span> <span class="na">rel=</span><span class="s">&quot;alternate&quot;</span>
<span class="na">href=</span><span class="s">&quot;/entry/3&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;link</span> <span class="na">rel=</span><span class="s">&quot;related&quot;</span>
<span class="na">type=</span><span class="s">&quot;text/html&quot;</span>
<span class="na">href=</span><span class="s">&quot;http://search.example.com/&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;link</span> <span class="na">rel=</span><span class="s">&quot;via&quot;</span>
<span class="na">type=</span><span class="s">&quot;text/html&quot;</span>
<span class="na">href=</span><span class="s">&quot;http://toby.example.com/examples/atom10&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;link</span> <span class="na">rel=</span><span class="s">&quot;enclosure&quot;</span>
<span class="na">type=</span><span class="s">&quot;video/mpeg4&quot;</span>
<span class="na">href=</span><span class="s">&quot;http://www.example.com/movie.mp4&quot;</span>
<span class="na">length=</span><span class="s">&quot;42301&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;id&gt;</span>tag:feedparser.org,2005-11-09:/docs/examples/atom10.xml:3<span class="nt">&lt;/id&gt;</span>
<span class="nt">&lt;published&gt;</span>2005-11-09T00:23:47Z<span class="nt">&lt;/published&gt;</span>
<span class="nt">&lt;updated&gt;</span>2005-11-09T11:56:34Z<span class="nt">&lt;/updated&gt;</span>
<span class="nt">&lt;summary</span> <span class="na">type=</span><span class="s">&quot;text/plain&quot;</span> <span class="na">mode=</span><span class="s">&quot;escaped&quot;</span><span class="nt">&gt;</span>Watch out for nasty tricks<span class="nt">&lt;/summary&gt;</span>
<span class="nt">&lt;content</span> <span class="na">type=</span><span class="s">&quot;application/xhtml+xml&quot;</span> <span class="na">mode=</span><span class="s">&quot;xml&quot;</span>
<span class="na">xml:base=</span><span class="s">&quot;http://example.org/entry/3&quot;</span> <span class="na">xml:lang=</span><span class="s">&quot;en-US&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;div</span> <span class="na">xmlns=</span><span class="s">&quot;http://www.w3.org/1999/xhtml&quot;</span><span class="nt">&gt;</span>Watch out for
<span class="nt">&lt;span</span> <span class="na">style=</span><span class="s">&quot;background: url(javascript:window.location=&#39;http://example.org/&#39;)&quot;</span><span class="nt">&gt;</span>
nasty tricks<span class="nt">&lt;/span&gt;&lt;/div&gt;</span>
<span class="nt">&lt;/content&gt;</span>
<span class="nt">&lt;/entry&gt;</span>
<span class="nt">&lt;/feed&gt;</span>
</pre></div>
</div>
<p>The feed elements are available in <tt class="docutils literal"><span class="pre">d.feed</span></tt>.</p>
<div class="section" id="accessing-common-feed-elements">
<h2>Accessing Common Feed Elements<a class="headerlink" href="#accessing-common-feed-elements" 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="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">feed</span><span class="o">.</span><span class="n">title</span>
<span class="go">u&#39;Sample feed&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">feed</span><span class="o">.</span><span class="n">link</span>
<span class="go">u&#39;http://example.org/&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">feed</span><span class="o">.</span><span class="n">subtitle</span>
<span class="go">u&#39;For documentation &lt;em&gt;only&lt;/em&gt;&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">feed</span><span class="o">.</span><span class="n">updated</span>
<span class="go">u&#39;2005-11-09T11:56:34Z&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">feed</span><span class="o">.</span><span class="n">updated_parsed</span>
<span class="go">(2005, 11, 9, 11, 56, 34, 2, 313, 0)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">feed</span><span class="o">.</span><span class="n">id</span>
<span class="go">u&#39;tag:feedparser.org,2005-11-09:/docs/examples/atom10.xml&#39;</span>
</pre></div>
</div>
<p>Entries are available in <tt class="docutils literal"><span class="pre">d.entries</span></tt>, which is a list. You access entries in
the order in which they appear in the original feed, so the first entry is
<tt class="docutils literal"><span class="pre">d.entries[0]</span></tt>.</p>
</div>
<div class="section" id="accessing-common-entry-elements">
<h2>Accessing Common Entry Elements<a class="headerlink" href="#accessing-common-entry-elements" 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="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">entries</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">title</span>
<span class="go">u&#39;First entry title&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">entries</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">link</span>
<span class="go">u&#39;http://example.org/entry/3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">entries</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">id</span>
<span class="go">u&#39;tag:feedparser.org,2005-11-09:/docs/examples/atom10.xml:3&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">entries</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">published</span>
<span class="go">u&#39;2005-11-09T00:23:47Z&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">entries</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">published_parsed</span>
<span class="go">(2005, 11, 9, 0, 23, 47, 2, 313, 0)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">entries</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">updated</span>
<span class="go">u&#39;2005-11-09T11:56:34Z&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">entries</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">updated_parsed</span>
<span class="go">(2005, 11, 9, 11, 56, 34, 2, 313, 0)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">entries</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">summary</span>
<span class="go">u&#39;Watch out for nasty tricks&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">.</span><span class="n">entries</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">content</span>
<span class="go">[{&#39;type&#39;: u&#39;application/xhtml+xml&#39;,</span>
<span class="go">&#39;base&#39;: u&#39;http://example.org/entry/3&#39;,</span>
<span class="go">&#39;language&#39;: u&#39;en-US&#39;,</span>
<span class="go">&#39;value&#39;: u&#39;&lt;div&gt;Watch out for &lt;span&gt;nasty tricks&lt;/span&gt;&lt;/div&gt;&#39;}]</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The parsed summary and content are not the same as they appear in the
original feed. The original elements contained dangerous <abbr title="HyperText Markup Language">HTML</abbr> markup which was sanitized. See
<a class="reference internal" href="html-sanitization.html#advanced-sanitization"><em>Sanitization</em></a> for details.</p>
</div>
<p>Because Atom entries can have more than one content element,
<tt class="docutils literal"><span class="pre">d.entries[0].content</span></tt> 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 <tt class="docutils literal"><span class="pre">d.entries[0].content[0].type</span></tt>, and the
actual content value, in <tt class="docutils literal"><span class="pre">d.entries[0].content[0].value</span></tt>.</p>
<p>You can get this level of detail on other Atom elements too.</p>
</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="#">Common Atom Elements</a><ul>
<li><a class="reference internal" href="#accessing-common-feed-elements">Accessing Common Feed Elements</a></li>
<li><a class="reference internal" href="#accessing-common-entry-elements">Accessing Common Entry Elements</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="common-rss-elements.html"
                        title="previous chapter">Common <abbr title="Rich Site Summary">RSS</abbr> Elements</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="atom-detail.html"
                        title="next chapter">Getting Detailed Information on Atom Elements</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/common-atom-elements.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="atom-detail.html" title="Getting Detailed Information on Atom Elements"
             >next</a> |</li>
        <li class="right" >
          <a href="common-rss-elements.html" title="Common RSS Elements"
             >previous</a> |</li>
        <li><a href="index.html">feedparser 5.1.3 documentation</a> &raquo;</li>
          <li><a href="basic.html" >Basic 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>