5

I'm very new to Feedparser and have returned to Python after a long break so would appreciate any help. I've tried the docs, which are very good, but I'm still slightly lagging.

How would I get Feedparser to take an rss feed and from that get the title and description of the first 10 items and label each item independently so that they can be inserted anywhere into other code? ie. I could just use the title of the first and second items with descriptions from others?

Hope that makes sense! Any help much appreciated

James Wanchai
  • 2,861
  • 4
  • 21
  • 16
  • You asked an almost identical question yesterday and it's still not clear what you're asking for. – FogleBird Feb 24 '10 at 14:28
  • OK, sorry, I was trying to make it clearer. Each rss feed has a certain number of items, each of which are stories. Each of these items has a different title. So, if I parsed that using Feedparser, how would I use just the title and description of the third item? Hope that makes more sense! – James Wanchai Feb 26 '10 at 08:56

1 Answers1

6
import feedparser
f = feedparser.parse('http://domain/feed')
# f contains a dictionary key 'entries'
# entries is a list of dictionaries with 'title' and 'content' keys
for e in f['entries']:
    print(e.get('title', ''))
    print(e.get('summary', ''))

Hope that helps.

Kurt McKee
  • 1,410
  • 13
  • 17
  • It looks like this snippet of code is now returning an invalid syntax error (pastebin.com/UqFGdYJz). Could this be an issue with Python 3 compatibility? – nitrl Sep 17 '13 at 17:05
  • 1
    @nitrl This isn't syntax for Python 3. :) –  Oct 27 '13 at 14:13
  • 1
    In Python 3, `print` is a function, rather than a statement. It therefore requires braces: `print()`. – Richard Horrocks Mar 12 '14 at 16:36