Skip to main content
 首页 » 编程设计

python之在 python 中显示列表项

2025年05月04日9Leo_wl

我想使用提要解析器操作包含经常更新(随时间)内容的提要。目标是显示更新提要的所有内容。

import feedparser 
d = feedparser.parse("some URL") 
 
print "Information of user"  
i = range(10) 
 
for i in d: 
    print d.entries[i].summary  
 
print " "  

由于解析数据是列表,列表不接受字符串作为索引,所以显示错误

喜欢:

File "F:\JavaWorkspace\Test\src\rss_parse.py", line 18, in <module> 
print d.entries[i].summary  
TypeError: list indices must be integers 

那我怎样才能得到所有的内容呢?任何人都可以告诉我一些关于这个问题的信息吗?提前致谢!

请您参考如下方法:

for i in range(10): 
    print d.entries[i].summary