所以我有一个这样的 XML:
<main>
<site>Amazon</site>
<url>..</url>
<books>
<book>
<id>1</id>
<author>Jhon</author>
</book>
<book>
<id>2</id>
<author>Jhon</author>
</book>
<book>
<id>3</id>
<author>Jhon</author>
</book>
</books>
</main>
我正在访问它:
document = xmltodict.parse(xml)
books = document['books]['book'] #returns 3
for book in books:
pass
但如果 XML 是这样的:
<books>
<book>
<id>3</id>
<author>Jhon</author>
</book>
</books>
然后返回2而不是1 ,它是<books>
我究竟做错了什么?