A
A
askhabaliev2021-04-09 17:51:27
Python
askhabaliev, 2021-04-09 17:51:27

How to output all child elements in 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 по отдельности

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-04-09
@askhabaliev

for item in root.findall('.//Valute'):
  id_ = item.attrib.get('ID')
  for child in item.getchildren():
    print(child.tag, child.text)
  print()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question