Python和FeedParser问题
问题描述:
我是Python新手。我有使用Feedparser的代码:Python和FeedParser问题
import feedparser
d = feedparser.parse('http://pplware.sapo.pt/feed/')
i = range(10)
for i in range(10):
updates = [{"url": d.entries[i].link, "msg": d.entries[i].summary + ", "}]
我的问题。
如何添加到变量“更新”的10个条目?
最好的问候,
答
import feedparser
d = feedparser.parse('http://pplware.sapo.pt/feed/')
updates = []
for i in range(10):
updates.append({"url": d.entries[i].link, "msg": d.entries[i].summary + ", "})
在你的循环,你追加dictionnary结果的更新列表。 'updates'包含for循环之后的10个元素。每个条目一个。
编辑:
然而,RestRisiko提供的代码确实更漂亮;-)
答
d = feedparser.parse('http://pplware.sapo.pt/feed/')
for item in d.entries[:10]:
print item
提取从“项目”的信息并将其添加到列表或字典是 基本用法Python列表和字典(请阅读本例中的教程 - 我们不能在这里教授列表和字典的基本用法)。
+0
感谢您的回复。它需要将值存储在一个变量中。 – 2011-03-29 17:24:16
+0
然后做吧! :) – 2011-03-29 18:01:00
谢谢!有效。 – 2011-03-29 17:23:40