Во-первых, здесь вы найдете все примеры для базового c извлечения
https://docs.python.org/3/library/xml.etree.elementtree.html#tutorial
2-й, ваши xml должны быть лучше структурированы: например "pouplar_shelves" - это ошибка опечатки
3-й, я приведу небольшой пример
import xml.etree.ElementTree as ET
xml = '''
<popular_shelves>
<shelf name="to-read" count="3504"/>
<shelf name="picture-books" count="397"/>
<shelf name="childrens" count="226"/>
<shelf name="children-s-books" count="213"/>
<shelf name="children" count="149"/>
<shelf name="children-s" count="139"/>
<shelf name="caldecott" count="110"/>
</popular_shelves>
'''
xml_root = ET.fromstring(xml)
for i in xml_root.iter():
print(i.tag, i.attrib)
В результате:
popular_shelves {}
shelf {'name': 'to-read', 'count': '3504'}
shelf {'name': 'picture-books', 'count': '397'}
shelf {'name': 'childrens', 'count': '226'}
shelf {'name': 'children-s-books', 'count': '213'}
shelf {'name': 'children', 'count': '149'}
shelf {'name': 'children-s', 'count': '139'}
shelf {'name': 'caldecott', 'count': '110'}
Press any key to continue . . .
Редактировать:
Вы должны лучше понять, что я послал в документах Python. Кроме того, ознакомьтесь с исходным кодом ET
https://github.com/python/cpython/blob/3.8/Lib/xml/etree/ElementTree.py
Это модель
Example form:
<tag attrib>text<child/>...</tag>tail
Используя полку в качестве примера:
for i in xml_root.iter('shelf'):
print(i.attrib)
Вернет это:
{'name': 'to-read', 'count': '3504'}
{'name': 'picture-books', 'count': '397'}
{'name': 'childrens', 'count': '226'}
{'name': 'children-s-books', 'count': '213'}
{'name': 'children', 'count': '149'}
{'name': 'children-s', 'count': '139'}
{'name': 'caldecott', 'count': '110'}
Bcz Ваш тег XML находится на полке, а ваши атрибуты - это имя, а количество - переведенный текст ... tail