2
Hello :)
I am trying to capture data from an xml to use in a search using python, but my algorithm is only returned the data from the last tags, example: The xml is found in http://legis.senado.gov.br/dadosabertos/senador/lista/atual?uf=sp and within it, there are three tags containing the data of parliamentarians, the tags have the name "Parliamentary", when running the code, the same only returns the data of the last parliamentarian and not the data of the 3, follows code used:
import requests
import xmltodict
import dicttoxml
from xml.etree import ElementTree as elements
URL = "http://legis.senado.gov.br/dadosabertos/senador/lista/atual?uf=sp"
dados = requests.get(url=URL)
dadosx = xmltodict.parse(dados.content)
dadosxml = dicttoxml.dicttoxml(dadosx)
root = elements.fromstring(dadosxml)
levels = root.findall('.//IdentificacaoParlamentar')
for level in levels:
name = level.find('NomeParlamentar').text
code = level.find('CodigoParlamentar').text
print name, code
This code is only returning me:
Marta Suplicy 5000
Could someone tell me where I’m going wrong?
Thanks for your attention :)
Thank you very much Barbetta, I’ll read the reference you gave me ;)
– Mário Sérgio Dias