Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from xml.etree.ElementTree import parse
- class XMLNamespace:
- def __init__(self, **kwargs):
- self.namespaces = {}
- for nombre, uri in kwargs.items():
- self.registrar(nombre, uri)
- def registrar(self, nombre, uri):
- self.namespaces[nombre] = '{' + uri + '}'
- def __call__(self, ruta):
- return ruta.format_map(self.namespaces)
- documento = parse('documento_web.xml')
- ns = XMLNamespace(html='http://www.w3.org/1999/xhtml')
- elemento = documento.find(ns('content/{html}html'))
- print(elemento)
- texto = documento.findtext(ns('content/{html}html/{html}head/{html}title'))
- print(texto)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement