我正在尝试通过python处理美味的RSS源。这里有一个例子:通过xml.dom.minidom处理RSS/RDF
...
<item rdf:about="http://weblist.me/">
<title>WebList - The Place To Find The Best List On The Web</title>
<dc:date>2009-12-24T17:46:14Z</dc:date>
<link>http://weblist.me/</link>
...
</item>
<item rdf:about="http://thumboo.com/">
<title>Thumboo! Free Website Thumbnails and PHP Script to Generate Web Screenshots</title>
<dc:date>2006-10-24T18:11:32Z</dc:date>
<link>http://thumboo.com/</link>
...
相关的代码是:
def getText(nodelist):
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc
dom = xml.dom.minidom.parse(file)
items = dom.getElementsByTagName("item")
for i in items:
title = i.getElementsByTagName("title")
print getText(title)
我认为这会打印出每一个标题,而是我得到基本上得到空白输出。我确信我在做一些愚蠢的错误,但不知道是什么?
你有没有试过http://feedparser.org/? – badp 2010-03-31 07:58:28
这是一个简单的RSS源,它与RDF无关。 XML中有一些属性是从RDF名称空间导入的,但Feed仍然是RSS源。请更正您问题的标题以反映此问题。 – 2010-03-31 09:00:50
'getElementsByTagName'返回'ELEMENT_NODE'列表,所以每次检查到'TEXT_NODE'失败。我没有测试,但我很确定这一点。 – 2010-03-31 09:10:01