<!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>Content Normalization — 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="Advanced Features" href="advanced.html" /> <link rel="next" title="Namespace Handling" href="namespace-handling.html" /> <link rel="prev" title="Sanitization" href="html-sanitization.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="namespace-handling.html" title="Namespace Handling" accesskey="N">next</a> |</li> <li class="right" > <a href="html-sanitization.html" title="Sanitization" accesskey="P">previous</a> |</li> <li><a href="index.html">feedparser 5.1.3 documentation</a> »</li> <li><a href="advanced.html" accesskey="U">Advanced Features</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="content-normalization"> <span id="advanced-normalization"></span><h1>Content Normalization<a class="headerlink" href="#content-normalization" title="Permalink to this headline">¶</a></h1> <p><strong class="program">Universal Feed Parser</strong> can parse many different types of feeds: Atom, <abbr title="Channel Definition Format">CDF</abbr>, and nine different versions of <abbr title="Rich Site Summary">RSS</abbr>. You should not be forced to learn the differences between these formats. <strong class="program">Universal Feed Parser</strong> does its best to ensure that you can treat all feeds the same way, regardless of format or version.</p> <p>You can access the basic elements of an Atom feed using <abbr title="Rich Site Summary">RSS</abbr> terminology.</p> <div class="section" id="accessing-an-atom-feed-as-an-rss-feed"> <h2>Accessing an Atom feed as an <abbr title="Rich Site Summary">RSS</abbr> feed<a class="headerlink" href="#accessing-an-atom-feed-as-an-rss-feed" title="Permalink to this headline">¶</a></h2> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">feedparser</span> <span class="gp">>>> </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">'http://feedparser.org/docs/examples/atom10.xml'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">d</span><span class="p">[</span><span class="s">'channel'</span><span class="p">][</span><span class="s">'title'</span><span class="p">]</span> <span class="go">u'Sample Feed'</span> <span class="gp">>>> </span><span class="n">d</span><span class="p">[</span><span class="s">'channel'</span><span class="p">][</span><span class="s">'link'</span><span class="p">]</span> <span class="go">u'http://example.org/'</span> <span class="gp">>>> </span><span class="n">d</span><span class="p">[</span><span class="s">'channel'</span><span class="p">][</span><span class="s">'description'</span><span class="p">]</span> <span class="go">u'For documentation <em>only</em></span> <span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s">'items'</span><span class="p">])</span> <span class="go">1</span> <span class="gp">>>> </span><span class="n">e</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s">'items'</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="gp">>>> </span><span class="n">e</span><span class="p">[</span><span class="s">'title'</span><span class="p">]</span> <span class="go">u'First entry title'</span> <span class="gp">>>> </span><span class="n">e</span><span class="p">[</span><span class="s">'link'</span><span class="p">]</span> <span class="go">u'http://example.org/entry/3'</span> <span class="gp">>>> </span><span class="n">e</span><span class="p">[</span><span class="s">'description'</span><span class="p">]</span> <span class="go">u'Watch out for nasty tricks'</span> <span class="gp">>>> </span><span class="n">e</span><span class="p">[</span><span class="s">'author'</span><span class="p">]</span> <span class="go">u'Mark Pilgrim (mark@example.org)'</span> </pre></div> </div> <p>The same thing works in reverse: you can access <abbr title="Rich Site Summary">RSS</abbr> feeds as if they were Atom feeds.</p> </div> <div class="section" id="accessing-an-rss-feed-as-an-atom-feed"> <h2>Accessing an <abbr title="Rich Site Summary">RSS</abbr> feed as an Atom feed<a class="headerlink" href="#accessing-an-rss-feed-as-an-atom-feed" title="Permalink to this headline">¶</a></h2> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">feedparser</span> <span class="gp">>>> </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">' http://feedparser.org/docs/examples/rss20.xml'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">d</span><span class="o">.</span><span class="n">feed</span><span class="o">.</span><span class="n">subtitle_detail</span> <span class="go">{'type': 'text/html',</span> <span class="go">'base': 'http://feedparser.org/docs/examples/rss20.xml',</span> <span class="go">'language': None,</span> <span class="go">'value': u'For documentation <em>only</em>'}</span> <span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">entries</span><span class="p">)</span> <span class="go">1</span> <span class="gp">>>> </span><span class="n">e</span> <span class="o">=</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="gp">>>> </span><span class="n">e</span><span class="o">.</span><span class="n">links</span> <span class="go">[{'rel': 'alternate',</span> <span class="go">'type': 'text/html',</span> <span class="go">'href': u'http://example.org/item/1'}]</span> <span class="gp">>>> </span><span class="n">e</span><span class="o">.</span><span class="n">summary_detail</span> <span class="go">{'type': 'text/html',</span> <span class="go">'base': 'http://feedparser.org/docs/examples/rss20.xml',</span> <span class="go">'language': u'en',</span> <span class="go">'value': u'Watch out for <span>nasty tricks</span>'}</span> <span class="gp">>>> </span><span class="n">e</span><span class="o">.</span><span class="n">updated_parsed</span> <span class="go">(2002, 9, 5, 0, 0, 1, 3, 248, 0)</span> </pre></div> </div> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">For more examples of how <strong class="program">Universal Feed Parser</strong> normalizes content from different formats, see <a class="reference internal" href="annotated-examples.html#annotated"><em>Annotated Examples</em></a>.</p> </div> </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="#">Content Normalization</a><ul> <li><a class="reference internal" href="#accessing-an-atom-feed-as-an-rss-feed">Accessing an Atom feed as an <abbr title="Rich Site Summary">RSS</abbr> feed</a></li> <li><a class="reference internal" href="#accessing-an-rss-feed-as-an-atom-feed">Accessing an <abbr title="Rich Site Summary">RSS</abbr> feed as an Atom feed</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="html-sanitization.html" title="previous chapter">Sanitization</a></p> <h4>Next topic</h4> <p class="topless"><a href="namespace-handling.html" title="next chapter">Namespace Handling</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="_sources/content-normalization.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="namespace-handling.html" title="Namespace Handling" >next</a> |</li> <li class="right" > <a href="html-sanitization.html" title="Sanitization" >previous</a> |</li> <li><a href="index.html">feedparser 5.1.3 documentation</a> »</li> <li><a href="advanced.html" >Advanced Features</a> »</li> </ul> </div> <div class="footer"> © 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>