<!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>Introduction — 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="Common RSS Elements" href="common-rss-elements.html" /> <link rel="prev" title="Basic Features" href="basic.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="common-rss-elements.html" title="Common RSS Elements" accesskey="N">next</a> |</li> <li class="right" > <a href="basic.html" title="Basic Features" accesskey="P">previous</a> |</li> <li><a href="index.html">feedparser 5.1.3 documentation</a> »</li> <li><a href="basic.html" accesskey="U">Basic Features</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="introduction"> <h1>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h1> <p><strong class="program">Universal Feed Parser</strong> is a <strong class="program">Python</strong> module for downloading and parsing syndicated feeds. It can handle <abbr title="Rich Site Summary">RSS</abbr> 0.90, Netscape <abbr title="Rich Site Summary">RSS</abbr> 0.91, Userland <abbr title="Rich Site Summary">RSS</abbr> 0.91, <abbr title="Rich Site Summary">RSS</abbr> 0.92, <abbr title="Rich Site Summary">RSS</abbr> 0.93, <abbr title="Rich Site Summary">RSS</abbr> 0.94, <abbr title="Rich Site Summary">RSS</abbr> 1.0, <abbr title="Rich Site Summary">RSS</abbr> 2.0, Atom 0.3, Atom 1.0, and <abbr title="Channel Definition Format">CDF</abbr> feeds. It also parses several popular extension modules, including Dublin Core and Apple’s <strong class="program">iTunes</strong> extensions.</p> <p>To use <strong class="program">Universal Feed Parser</strong>, you will need <strong class="program">Python</strong> 2.4 or later (Python 3 is supported). <strong class="program">Universal Feed Parser</strong> is not meant to run standalone; it is a module for you to use as part of a larger <strong class="program">Python</strong> program.</p> <p><strong class="program">Universal Feed Parser</strong> is easy to use; the module is self-contained in a single file, <tt class="file docutils literal"><span class="pre">feedparser.py</span></tt>, and it has one primary public function, <tt class="docutils literal"><span class="pre">parse</span></tt>. <tt class="docutils literal"><span class="pre">parse</span></tt> takes a number of arguments, but only one is required, and it can be a <abbr title="Uniform Resource Locator">URL</abbr>, a local filename, or a raw string containing feed data in any format.</p> <div class="section" id="parsing-a-feed-from-a-remote-url"> <h2>Parsing a feed from a remote <abbr title="Uniform Resource Locator">URL</abbr><a class="headerlink" href="#parsing-a-feed-from-a-remote-url" 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">'feed'</span><span class="p">][</span><span class="s">'title'</span><span class="p">]</span> <span class="go">u'Sample Feed'</span> </pre></div> </div> <p>The following example assumes you are on Windows, and that you have saved a feed at <tt class="file docutils literal"><span class="pre">c:\incoming\atom10.xml</span></tt>.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last"><strong class="program">Universal Feed Parser</strong> works on any platform that can run <strong class="program">Python</strong>; use the path syntax appropriate for your platform.</p> </div> </div> <div class="section" id="parsing-a-feed-from-a-local-file"> <h2>Parsing a feed from a local file<a class="headerlink" href="#parsing-a-feed-from-a-local-file" 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">r'c:\incoming\atom10.xml'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">d</span><span class="p">[</span><span class="s">'feed'</span><span class="p">][</span><span class="s">'title'</span><span class="p">]</span> <span class="go">u'Sample Feed'</span> </pre></div> </div> <p><strong class="program">Universal Feed Parser</strong> can also parse a feed in memory.</p> </div> <div class="section" id="parsing-a-feed-from-a-string"> <h2>Parsing a feed from a string<a class="headerlink" href="#parsing-a-feed-from-a-string" 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">rawdata</span> <span class="o">=</span> <span class="s">"""<rss version="2.0"></span> <span class="go"><channel></span> <span class="go"><title>Sample Feed</title></span> <span class="go"></channel></span> <span class="go"></rss>"""</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="n">rawdata</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">d</span><span class="p">[</span><span class="s">'feed'</span><span class="p">][</span><span class="s">'title'</span><span class="p">]</span> <span class="go">u'Sample Feed'</span> </pre></div> </div> <p>Values are returned as <strong class="program">Python</strong> Unicode strings (except when they’re not – see <a class="reference internal" href="character-encoding.html#advanced-encoding"><em>Character Encoding Detection</em></a> for all the gory details).</p> <div class="admonition-see-also admonition seealso"> <p class="first admonition-title">See also</p> <p class="last"><a class="reference external" href="http://docs.python.org/tut/node5.html#SECTION005130000000000000000">Introduction to Python Unicode strings</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="#">Introduction</a><ul> <li><a class="reference internal" href="#parsing-a-feed-from-a-remote-url">Parsing a feed from a remote <abbr title="Uniform Resource Locator">URL</abbr></a></li> <li><a class="reference internal" href="#parsing-a-feed-from-a-local-file">Parsing a feed from a local file</a></li> <li><a class="reference internal" href="#parsing-a-feed-from-a-string">Parsing a feed from a string</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="basic.html" title="previous chapter">Basic Features</a></p> <h4>Next topic</h4> <p class="topless"><a href="common-rss-elements.html" title="next chapter">Common <abbr title="Rich Site Summary">RSS</abbr> Elements</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="_sources/introduction.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="common-rss-elements.html" title="Common RSS Elements" >next</a> |</li> <li class="right" > <a href="basic.html" title="Basic Features" >previous</a> |</li> <li><a href="index.html">feedparser 5.1.3 documentation</a> »</li> <li><a href="basic.html" >Basic 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>