@askhabaliev

Как вывести все дочерние элементы в xml.etree.ElementTree?

import xml.etree.ElementTree as et
import requests

url = 'http://www.cbr.ru/scripts/XML_daily.asp'
root = et.fromstring(requests.get(url).content)


for item in root.findall('.//Valute'):
	ids = print(item.attrib.get('ID'))
	if ids:
		pass
	else:
		continue
	for s in root.findall(".//[@%s]" %ids):
		print(s)//нужно чтобы тут выводились все данные о валюте для каждого id по отдельности
  • Вопрос задан
  • 557 просмотров
Решения вопроса 1
SoreMix
@SoreMix Куратор тега Python
yellow
for item in root.findall('.//Valute'):
  id_ = item.attrib.get('ID')
  for child in item.getchildren():
    print(child.tag, child.text)
  print()
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы