elementtree非常新,所以我尝试为xbmc的tv插件解析xml文件。下面是我遇到问题的代码。我认为我的xpath不正确,placeholder不能处理属性!在
这是我正在处理的xml文件-http://services.tvrage.com/myfeeds/episode_list.php?key=ag6txjP0RH4m0c8sZk2j&sid=2930
seasonnum = root2.findall("/Show/Episodelist/Season[@no='%s']/episode/seasonnum" % (season))
import xml.etree.ElementTree as ET
import urllib
tree2 = ET.parse(urllib.urlopen(url))
root2 = tree2.getroot()
seasonnum = tree2.findall("./Episodelist/Season[@no='%s']/episode/seasonnum" % '1')
print seasonnum
需要synrror分隔符[)是什么
我试过你的例子,而且很管用。以下是一个浓缩的完整版本:
我能想到的唯一问题是,不知何故,您下载了部分XML文档——不太可能,但我不知道其他任何解释。请注意,上面的脚本取自您的问题。我只添加了
for
循环。在根据^{} documentation - XPath support :
您可能需要像^{} 这样的第三方库来使用XPath。在
示例:
更新
要使用
^{pr2}$lxml.etree.ElementTree
,应该稍微修改xpath:使用ElementTree:
相关问题 更多 >
编程相关推荐