XML = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Entities TotalResults="101" PageSize="100" PageNumber="1">
<Entity Type="run">
<Fields>
<Field Name="host">
<Value>osdc-vw64</Value>
</Field>
<Field Name="status">
<Value>Passed</Value>
</Field>
<Field Name="owner">
<Value>Aspeg</Value>
</Field>
<Field Name="user-template-01">
<Value>1941896</Value>
</Field>
<Field Name="test-id">
<Value>72769</Value>
</Field>
</Fields>
</Entity>
<Entity Type="run">
<Fields>
<Field Name="host">
<Value>osdc-57</Value>
</Field>
<Field Name="status">
<Value>Passed</Value>
</Field>
<Field Name="owner">
<Value>spana</Value>
</Field>
<Field Name="user-template-01">
<Value>1941896</Value>
</Field>
<Field Name="test-id">
<Value>72769</Value>
</Field>
</Fields>
</Entity>
</Entities>"""
我用过:
from xml.etree import ElementTree as ET
root = ET.fromstring(XML)
print root.tag
我不知道现在该怎么办。。。你知道吗
最简单的方法是使用PyQuery(如果您了解jQuery选择器):
由于您有多个Name='host'的元素,因此应该迭代实体:
使用
lxml.etree
:注意:我对
lxml
模块非常糟糕,有人可能会想出比这个更好的解决方案:)我的输出是:相关问题 更多 >
编程相关推荐