我有这样的 XML:(这是汤变量)
<?xml version="1.0" encoding="utf-8"?>
<results>
<status code="ok">
</status>
<principal-list>
<principal account-id="1013353221" has-children="false" is-hidden="false" is-primary="false" principal-id="1013353225" training-group-id="" type="user">
<name>
First Last
</name>
<login>
first.last
</login>
<email>
first.last@domain.com
</email>
<display-uid>
first.last
</display-uid>
</principal>
<principal account-id="1013353221" has-children="false" is-hidden="false" is-primary="false" principal-id="1115269931" training-group-id="" type="user">
<name>
First Last
</name>
<login>
first.last
</login>
<email>
first.last@domain.com
</email>
<display-uid>
first.last
</display-uid>
</principal>
</principal-list>
</results>
我试过这段代码:
loginlist = [el.string for el in soup.findAll('login')]
for entry in loginlist:
print entry
它返回:
first.last
对于每个用户。
我还想找到principal-id
嵌套的login
我的输出看起来像:
`'first.last', '1013353225'`
`'first.last', '1115269931'`