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

浪尽此生 提交于 2019-12-02 04:10:01

Your second approach is OK, but as you append the feeds into a list, you also will get a list of feeds of entries, thus:

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

or to make a flat list of all posts, extend the list with the list of new entries from each url:

posts = []
for url in RSS_URLS:
    posts.extend(feedparser.parse(url).entries)

for post in posts:
    print post.title
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!