introduction.rst 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. Introduction
  2. ============
  3. :program:`Universal Feed Parser` is a :program:`Python` module for downloading
  4. and parsing syndicated feeds. It can handle :abbr:`RSS (Rich Site Summary)`
  5. 0.90, Netscape :abbr:`RSS (Rich Site Summary)` 0.91, Userland :abbr:`RSS (Rich
  6. Site Summary)` 0.91, :abbr:`RSS (Rich Site Summary)` 0.92, :abbr:`RSS (Rich
  7. Site Summary)` 0.93, :abbr:`RSS (Rich Site Summary)` 0.94, :abbr:`RSS (Rich
  8. Site Summary)` 1.0, :abbr:`RSS (Rich Site Summary)` 2.0, Atom 0.3, Atom 1.0,
  9. and :abbr:`CDF (Channel Definition Format)` feeds. It also parses several
  10. popular extension modules, including Dublin Core and Apple's :program:`iTunes`
  11. extensions.
  12. To use :program:`Universal Feed Parser`, you will need :program:`Python` 2.4 or
  13. later (Python 3 is supported). :program:`Universal Feed Parser` is not meant
  14. to run standalone; it is a module for you to use as part of a larger
  15. :program:`Python` program.
  16. :program:`Universal Feed Parser` is easy to use; the module is self-contained
  17. in a single file, :file:`feedparser.py`, and it has one primary public
  18. function, ``parse``. ``parse`` takes a number of arguments, but only one is
  19. required, and it can be a :abbr:`URL (Uniform Resource Locator)`, a local
  20. filename, or a raw string containing feed data in any format.
  21. Parsing a feed from a remote :abbr:`URL (Uniform Resource Locator)`
  22. -------------------------------------------------------------------
  23. ::
  24. >>> import feedparser
  25. >>> d = feedparser.parse('http://feedparser.org/docs/examples/atom10.xml')
  26. >>> d['feed']['title']
  27. u'Sample Feed'
  28. The following example assumes you are on Windows, and that you have saved a feed at :file:`c:\\incoming\\atom10.xml`.
  29. .. note::
  30. :program:`Universal Feed Parser` works on any platform that can run
  31. :program:`Python`; use the path syntax appropriate for your platform.
  32. Parsing a feed from a local file
  33. --------------------------------
  34. ::
  35. >>> import feedparser
  36. >>> d = feedparser.parse(r'c:\incoming\atom10.xml')
  37. >>> d['feed']['title']
  38. u'Sample Feed'
  39. :program:`Universal Feed Parser` can also parse a feed in memory.
  40. Parsing a feed from a string
  41. ----------------------------
  42. ::
  43. >>> import feedparser
  44. >>> rawdata = """<rss version="2.0">
  45. <channel>
  46. <title>Sample Feed</title>
  47. </channel>
  48. </rss>"""
  49. >>> d = feedparser.parse(rawdata)
  50. >>> d['feed']['title']
  51. u'Sample Feed'
  52. Values are returned as :program:`Python` Unicode strings (except when they're
  53. not -- see :ref:`advanced.encoding` for all the gory details).
  54. .. seealso::
  55. `Introduction to Python Unicode strings <http://docs.python.org/tut/node5.html#SECTION005130000000000000000>`_