Hello:)
I'm trying to capture data from an xml to use in a search using python, however my algorithm is only returned the data of the last tags, eg: xml is in link and inside it, there are three tags containing the data of the parliamentarians, the tags have the name of" Parliamentarian ", when running the code , the same only returns the data of the last parliamentary and not the data of the 3, it 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 returning me only:
Marta Suplicy 5000
Could someone tell me where I'm wrong?
Thanks for the attention :)