uncommon-atom.rst 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. Uncommon Atom Elements
  2. ======================
  3. These elements are less common, but are useful for niche applications and may
  4. be present in any Atom feed.
  5. Besides an author, each Atom feed or entry can have an arbitrary number of
  6. contributors. :program:`Universal Feed Parser` makes these available as a
  7. list.
  8. Accessing contributors
  9. ----------------------
  10. ::
  11. >>> import feedparser
  12. >>> d = feedparser.parse('http://feedparser.org/docs/examples/atom10.xml')
  13. >>> e = d.entries[0]
  14. >>> len(e.contributors)
  15. 2
  16. >>> e.contributors[0]
  17. {'name': u'Joe',
  18. 'href': u'http://example.org/joe/',
  19. 'email': u'joe@example.org'}
  20. >>> e.contributors[1]
  21. {'name': u'Sam',
  22. 'href': u'http://example.org/sam/',
  23. 'email': u'sam@example.org'}
  24. Besides an alternate link, each Atom feed or entry can have an arbitrary number
  25. of other links. Each link is distinguished by its type attribute, which is a
  26. MIME-style content type, and its rel attribute.
  27. Accessing multiple links
  28. ------------------------
  29. ::
  30. >>> import feedparser
  31. >>> d = feedparser.parse('http://feedparser.org/docs/examples/atom10.xml')
  32. >>> e = d.entries[0]
  33. >>> len(e.links)
  34. 4
  35. >>> e.links[0]
  36. {'rel': u'alternate',
  37. 'type': u'text/html',
  38. 'href': u'http://example.org/entry/3'}
  39. >>> e.links[1]
  40. {'rel': u'related',
  41. 'type': u'text/html',
  42. 'href': u'http://search.example.com/'}
  43. >>> e.links[2]
  44. {'rel': u'via',
  45. 'type': u'text/html',
  46. 'href': u'http://toby.example.com/examples/atom10'}
  47. >>> e.links[3]
  48. {'rel': u'enclosure',
  49. 'type': u'video/mpeg4',
  50. 'href': u'http://www.example.com/movie.mp4',
  51. 'length': u'42301'}
  52. .. note::
  53. For more examples of accessing Atom elements, see the annotated examples
  54. :ref:`annotated.atom10` and :ref:`annotated.atom03`.