开发者

Feedparser newbie questions

After a break from Python(and I knew very little then!) I'm coming back to it for a project(hopefully!). I want to do some parsing using Feedparser & need a few hints to start. Before anyone shouts, I have searched Google and read the docs, but I'm a bit too rusty unfortunately!(So please don't lmgtfy me!)

If I have a rss feed开发者_运维技巧, then how would I parse it in order that I get each of the item titles seperately which can then be inserted into a web page?

Hope that makes sense. Many thanks for any responses.


import feedparser
url = "http://..."
feed = feedparser.parse(url)
for post in feed.entries:
    title = post.title
    print(title)

If you'd like to extract just the third post, then you could use

post=feed.entries[2]

(since python uses 0-based indexing). Printing post might be helpful; it'll show you what information is available:

print post

And finally, to grab just the title of the third post:

print post['title']

or

print post.title
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜