Sophie

Sophie

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

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>Content Normalization &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="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> &raquo;</li>
          <li><a href="advanced.html" accesskey="U">Advanced Features</a> &raquo;</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">&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="p">[</span><span class="s">&#39;channel&#39;</span><span class="p">][</span><span class="s">&#39;title&#39;</span><span class="p">]</span>
<span class="go">u&#39;Sample Feed&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="p">[</span><span class="s">&#39;channel&#39;</span><span class="p">][</span><span class="s">&#39;link&#39;</span><span class="p">]</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="p">[</span><span class="s">&#39;channel&#39;</span><span class="p">][</span><span class="s">&#39;description&#39;</span><span class="p">]</span>
<span class="go">u&#39;For documentation &lt;em&gt;only&lt;/em&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s">&#39;items&#39;</span><span class="p">])</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s">&#39;items&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="p">[</span><span class="s">&#39;title&#39;</span><span class="p">]</span>
<span class="go">u&#39;First entry title&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="p">[</span><span class="s">&#39;link&#39;</span><span class="p">]</span>
<span class="go">u&#39;http://example.org/entry/3&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="p">[</span><span class="s">&#39;description&#39;</span><span class="p">]</span>
<span class="go">u&#39;Watch out for nasty tricks&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="p">[</span><span class="s">&#39;author&#39;</span><span class="p">]</span>
<span class="go">u&#39;Mark Pilgrim (mark@example.org)&#39;</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">&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/rss20.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">subtitle_detail</span>
<span class="go">{&#39;type&#39;: &#39;text/html&#39;,</span>
<span class="go">&#39;base&#39;: &#39;http://feedparser.org/docs/examples/rss20.xml&#39;,</span>
<span class="go">&#39;language&#39;: None,</span>
<span class="go">&#39;value&#39;: u&#39;For documentation &lt;em&gt;only&lt;/em&gt;&#39;}</span>
<span class="gp">&gt;&gt;&gt; </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">&gt;&gt;&gt; </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">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">links</span>
<span class="go">[{&#39;rel&#39;: &#39;alternate&#39;,</span>
<span class="go">&#39;type&#39;: &#39;text/html&#39;,</span>
<span class="go">&#39;href&#39;: u&#39;http://example.org/item/1&#39;}]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">.</span><span class="n">summary_detail</span>
<span class="go">{&#39;type&#39;: &#39;text/html&#39;,</span>
<span class="go">&#39;base&#39;: &#39;http://feedparser.org/docs/examples/rss20.xml&#39;,</span>
<span class="go">&#39;language&#39;: u&#39;en&#39;,</span>
<span class="go">&#39;value&#39;: u&#39;Watch out for &lt;span&gt;nasty tricks&lt;/span&gt;&#39;}</span>
<span class="gp">&gt;&gt;&gt; </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> &raquo;</li>
          <li><a href="advanced.html" >Advanced 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>