uncommon-rss.rst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. Uncommon :abbr:`RSS (Rich Site Summary)` Elements
  2. =================================================
  3. These elements are less common, but are useful for niche applications and may
  4. be present in any :abbr:`RSS (Rich Site Summary)` feed.
  5. An :abbr:`RSS (Rich Site Summary)` feed can specify a small image which some
  6. aggregators display as a logo.
  7. Accessing feed image
  8. --------------------
  9. ::
  10. >>> import feedparser
  11. >>> d = feedparser.parse('http://feedparser.org/docs/examples/rss20.xml')
  12. >>> d.feed.image
  13. {'title': u'Example banner',
  14. 'href': u'http://example.org/banner.png',
  15. 'width': 80,
  16. 'height': 15,
  17. 'link': u'http://example.org/'}
  18. Feeds and entries can be assigned to multiple categories, and in some versions
  19. of :abbr:`RSS (Rich Site Summary)`, categories can be associated with a
  20. "domain". Both are free-form strings. For historical reasons,
  21. :program:`Universal Feed Parser` makes multiple categories available as a list
  22. of tuples, rather than a list of dictionaries.
  23. Accessing multiple categories
  24. -----------------------------
  25. ::
  26. >>> import feedparser
  27. >>> d = feedparser.parse('http://feedparser.org/docs/examples/rss20.xml')
  28. >>> d.feed.categories
  29. [(u'Syndic8', u'1024'),
  30. (u'dmoz', 'Top/Society/People/Personal_Homepages/P/')]
  31. Each item in an :abbr:`RSS (Rich Site Summary)` feed can have an "enclosure", a
  32. delightful misnomer that is simply a link to an external file (usually a music
  33. or video file, but any type of file can be "enclosed"). Once rare, this
  34. element has recently gained popularity due to the rise of
  35. `podcasting <http://en.wikipedia.org/wiki/Podcasting>`_. Some clients (such
  36. as Apple's :program:`iTunes`) may automatically download enclosures; others
  37. (such as the web-based Bloglines) may simply render each enclosure as a link.
  38. The :abbr:`RSS (Rich Site Summary)` specification states that there can be at
  39. most one enclosure per item. However, Atom entries may contain more than one
  40. enclosure per entry, so :program:`Universal Feed Parser` captures all of them
  41. and makes them available as a list.
  42. Accessing enclosures
  43. --------------------
  44. ::
  45. >>> import feedparser
  46. >>> d = feedparser.parse('http://feedparser.org/docs/examples/rss20.xml')
  47. >>> e = d.entries[0]
  48. >>> len(e.enclosures)
  49. 1
  50. >>> e.enclosures[0]
  51. {'type': u'audio/mpeg',
  52. 'length': u'1069871',
  53. 'href': u'http://example.org/audio/demo.mp3'}
  54. Accessing feed cloud
  55. --------------------
  56. No one is quite sure what a cloud is.
  57. ::
  58. >>> import feedparser
  59. >>> d = feedparser.parse('http://feedparser.org/docs/examples/rss20.xml')
  60. >>> d.feed.cloud
  61. {'domain': u'rpc.example.com',
  62. 'port': u'80',
  63. 'path': u'/RPC2',
  64. 'registerprocedure': u'pingMe',
  65. 'protocol': u'soap'}
  66. .. note::
  67. For more examples of accessing :abbr:`RSS (Rich Site Summary)` elements,
  68. see the annotated examples: :ref:`annotated.rss10`, :ref:`annotated.rss20`,
  69. and :ref:`annotated.rss20dc`.