我在django中使用lxml.etree.parse
来解析外部rss提要中的一些内容,并使用findall
来解决名称空间问题。在
我可以反复查看结果,但我无法显示结果中的任何文本。在
下面是我试图从中获取的xml文件的外观:
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Open Library : Author Name</title>
<link href="http://www.somedomain.org/people/atom/author_name" rel="self"/>
<updated>2012-03-20T16:41:00Z</updated>
<author>
<name>somedomain.org</name>
</author>
<id>tag:somedomain.org,2007:/person_feed/123456</id>
<entry>
<link href="http://www.somedomain.org/roll_call/show/1234" rel="alternate"/>
<id>
tag:somedomain.org,2012-03-20:/roll_call_vote/1234
</id>
<updated>2012-03-20T16:41:00Z</updated>
<title>Once upon a time</title>
<content type="html">
This is a book full of words
</content>
</entry>
</feed>
以下是我对django的看法:
^{pr2}$我也尝试过用xpath
代替findtext
,但是得到了相同的结果。在
"link":listing.xpath("link/text()"),
"title":listing.xpath("entry/link/text()"),
"content":listing.xpath("content/text()"),
感谢任何帮助。在
您没有考虑XML名称空间。在
必须定义前缀(即使XML中没有前缀)并在XPath表达式中使用它。这意味着您必须通知
.xpath()
您将为哪个名称空间使用哪个前缀,因此需要使用第二个参数。在相关问题 更多 >
编程相关推荐