使用Feedparser解析多個RSS提要,但此功能不起作用。我如何創建一個函數來解析提要並從提要條目中獲取鏈接以進一步推送推文?解析多個RSS提要(Python)
def get():
rss_url = [
'http://www.huffingtonpost.com/news/syria/feed/',
'http://www.nytimes.com/svc/collections/v1/publish /www.nytimes.com/topic/destination/syria/rss.xml',
]
def getHeadlines(rss_url):
feeds = []
for url in rss_url:
feeds.append(feedparser.parse(url))
for feed in feeds:
for post in feed.entries:
return post.link
tweet(getHeadlines(rss_url))
我能做到這一點,當我嘗試只是這一點 -
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
在這種情況下,「無功」意味着什麼?這種代碼以什麼方式不符合你的期望?請閱讀[問]提出有效問題的提示;這是你可以做的最大的事情,以增加獲得良好答案的機會。 – Chris
我期望代碼解析訂閱源並獲取訂閱源中每個條目的鏈接。當我定義一個函數時沒有這樣做。 – codenovice
請修正您的代碼塊的縮進。現在,不清楚getHeadlines()是什麼行,哪些行不是。 – Chris