1 2 3 4 5 6 7 8 9 10 11 |
from lxml import html html_doc = "<html><head><title>Mi Título</title></head><body><h1>Hola Mundo!</h1></body></html>" tree = html.fromstring(html_doc) # Modificar el título title = tree.xpath('//title')[0] title.text = "Nuevo Título" print(html.tostring(tree, pretty_print=True).decode()) |