我在一个xml响应上有这样的结构
<reponse xmls="http://www.some.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.some.com/ot ot.xsd ">
<OneTree> </OneTree>
<TwoTree>
<count>10</count>
<alist>
<aelement>
<Name>FirstEntry</Name>
</aelement>
<aelement>
<Name>FirstEntry</Name>
</aelement>
</alist>
</TwoTree>
我试图打印出名字上的值
到目前为止,我已经成功地打印了<count>
的值
tree = ElementTree.fromstring(response.content)
for child in tree:
if (child.tag == '{http://www.some.com/ot}TwoTree'):
print child[0].text
我在获取<alist>
上的树时遇到问题,打印出的名称、查找标记或属性不适用于此结构。帮个小忙
我认为使用接受basic XPath syntax的
findall()
方法更容易:complete demo:
输出:
相关问题 更多 >
编程相关推荐