【发布时间】:2017-10-28 22:32:17
【问题描述】:
Stackoverflow RSS 提要上的每个作业项都有特定的标签,键为“类别”。
看起来基本上是这样的:
<category>scala</category>
<category>hadoop</category>
<category>apache-spark</category>
<category>hive</category>
<category>json</category>
我想使用 Feedparser,将所有标签放入一个列表中。相反,我总是只得到第一个元素。 Feedparser 文档提到了entries[i].content,但我不确定这是否是正确的方法,或者在这种情况下如何使用它。
这是我的代码:
import feedparser
rss_url = "https://stackoverflow.com/jobs/feed"
feed = feedparser.parse(rss_url)
items = feed["items"]
for item in items:
title = item["title"]
try:
tags = []
tags.append(item["category"])
print(title + " " + str(tags))
except:
print("Failed")
【问题讨论】:
标签: python rss feedparser