簡體   English   中英

在Python中合並RSS Feed

[英]Merging RSS Feeds in Python

我正在嘗試使用python合並RSS feed,然后將其播放回網站。 在研究了推薦的方法之后,我選擇了以下代碼,該代碼基本上是推薦內容的直接副本:

    hit_list = ['http://www.bbc.co.uk/sport/football/teams/cardiff-city/rss.xml','http://www1.skysports.com/feeds/11704/news.xml','http://www.cardiffcity-mad.co.uk/rssfeeds/rssfull.asp']
    # pull down all feeds
    future_calls = [Future(feedparser.parse,rss_url) for rss_url in hit_list]
    # block until they are all in
    feeds = [future_obj() for future_obj in future_calls]

    #Now that you have your feeds, extract all the entries
    entries = []
    for feed in feeds:
        entries.extend(feed["items"])

    values['feeds'] = sorted(entries, key=lambda entry: entry["updated_parsed"])

稍后,我使用以下方式致電網絡:

template = jinja_environment.get_template('TeamView.html')
self.response.out.write(template.render(values))

最后,在我的html頁面中,我有:

 {% for r in feeds.entries %}
      <a href={{r.link}} target=_blank>{{r.title}}</a>: {{r.description}}
      <br/>
 {% endfor %}

當我分別對提要使用feedparser時,我可以傳遞信息,但是當我嘗試合並提要時,則沒有任何顯示。 我已經導入了feedparser和Future。

您的sorted()調用缺少結束括號。

我通過分解輸出找到了答案。 for循環是取出entrys標記並將其保留在較高級別的,因此我的html需要為:

{% for r in feeds %}
      <a href={{r.link}} target=_blank>{{r.title}}</a>: {{r.description}}
      <br/>
{% endfor %}

現在完美運作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM