5

我对 Feedparser 很陌生,经过长时间的休息后又回到了 Python,因此我将不胜感激。我已经尝试过文档,它们非常好,但我还是有点落后。

我如何让 Feedparser 获取 rss 提要并从中获取前 10 个项目的标题和描述,并独立标记每个项目,以便它们可以插入到其他代码的任何位置?IE。我可以将第一项和第二项的标题与其他人的描述一起使用吗?

希望这是有道理的!非常感谢任何帮助

4

1 回答 1

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', '')

希望有帮助。

于 2011-02-23T23:32:35.977 回答