Python XML parse this doc -
i couldn't find this, , can't use beautifulsoap. i've xml url doc. wanna parse items called contenido, has atribs , don't know how them. i've tried xml.sax don't know how use attrib
<contenido> <tipo>evento</tipo> <atributos idioma="es"> <atributo nombre="id-evento">8006941</atributo> <atributo nombre="titulo">582 mapas, compañía teatral “la cola del pavo”</atributo> <atributo nombre="tipo"> /contenido/actividades/recitalespresentacionesactosliterarios </atributo> </atributos> </contenido>
this example using xml.sax
import xml.sax class myhandler( xml.sax.contenthandler ): def __init__(self): self.is_atributo = false def startelement(self, tag, attributes): if tag == 'atributo': self.is_atributo = true def characters(self, content): if self.is_atributo: print(content) if __name__ == '__main__': parser = xml.sax.make_parser() parser.setfeature(xml.sax.handler.feature_namespaces, 0) handler = myhandler() parser.setcontenthandler(handler) parser.parse('your.xml')
Comments
Post a Comment