atom-detail.rst 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. Getting Detailed Information on Atom Elements
  2. =============================================
  3. Several Atom elements share the Atom content model: title, subtitle, rights,
  4. summary, and of course content. (Atom 0.3 also had an info element which
  5. shared this content model.) :program:`Universal Feed Parser` captures all
  6. relevant metadata about these elements, most importantly the content type and
  7. the value itself.
  8. Detailed Information on Feed Elements
  9. -------------------------------------
  10. ::
  11. >>> import feedparser
  12. >>> d = feedparser.parse('http://feedparser.org/docs/examples/atom10.xml')
  13. >>> d.feed.title_detail
  14. {'type': u'text/plain',
  15. 'base': u'http://example.org/',
  16. 'language': u'en',
  17. 'value': u'Sample Feed'}
  18. >>> d.feed.subtitle_detail
  19. {'type': u'text/html',
  20. 'base': u'http://example.org/',
  21. 'language': u'en',
  22. 'value': u'For documentation <em>only</em>'}
  23. >>> d.feed.rights_detail
  24. {'type': u'text/html',
  25. 'base': u'http://example.org/',
  26. 'language': u'en',
  27. 'value': u'<p>Copyright 2004, Mark Pilgrim</p>'}
  28. >>> d.entries[0].title_detail
  29. {'type': 'text/plain',
  30. 'base': u'http://example.org/',
  31. 'language': u'en',
  32. 'value': u'First entry title'}
  33. >>> d.entries[0].summary_detail
  34. {'type': u'text/plain',
  35. 'base': u'http://example.org/',
  36. 'language': u'en',
  37. 'value': u'Watch out for nasty tricks'}
  38. >>> len(d.entries[0].content)
  39. 1
  40. >>> d.entries[0].content[0]
  41. {'type': u'application/xhtml+xml',
  42. 'base': u'http://example.org/entry/3',
  43. 'language': u'en-US'
  44. 'value': u'<div>Watch out for <span> nasty tricks</span></div>'}