如何在 feedparser (Python) 中解析多个 URL?

How can I parse multiple URLs in feedparser (Python)?

我正在制作一个带有一些固定提要的小网络应用程序(固定的,你不能像在 Feedly 或 Google Reader 中那样添加提要)

我试过了,没有成功

RSS_URLS = [
    'http://feeds.feedburner.com/RockPaperShotgun',
    'http://www.gameinformer.com/b/MainFeed.aspx?Tags=preview',
    ]

feed = feedparser.parse(RSS_URLS)

for post in feed.entries:
    print post.title

而这个,运气不好

RSS_URLS = [
    'http://feeds.feedburner.com/RockPaperShotgun',
    'http://www.gameinformer.com/b/MainFeed.aspx?Tags=preview',
    ]

feed = []
for url in RSS_URLS:
    feed.append(feedparser.parse(url))

for post in feed.entries:
    print post.title

您的第二种方法没问题,但是当您将提要附加到列表中时, 您还将获得条目提要列表,因此:

RSS_URLS = [
    'http://feeds.feedburner.com/RockPaperShotgun',
    'http://www.gameinformer.com/b/MainFeed.aspx?Tags=preview',
    ]

feeds = []
for url in RSS_URLS:
    feeds.append(feedparser.parse(url))

for feed in feeds:
    for post in feed.entries:
        print post.title

或制作所有帖子的平面列表,extend 列表包含来自每个 url:

的新条目列表
posts = []
for url in RSS_URLS:
    posts.extend(feedparser.parse(url).entries)

for post in posts:
    print post.title