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

后端 未结 1 1628

I\'m making a little webapp with some fixed feeds (fixed as in, you can\'t add feeds like in Feedly or Google Reader)

I tried this, with no luck

RSS_URLS         


        
相关标签:
1条回答
  • 2021-01-23 19:19

    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
    
    0 讨论(0)
提交回复
热议问题