lxml.html

Table of Contents

References

Guide
https://lxml.de/lxmlhtml.html
HtmlElement specific
https://lxml.de/api/lxml.html.HtmlMixin-class.html

Parse HTML howto

from lxml import html
html.parse(str(path)).getroot()

Write HTML howto

etree = doc.getroottree()
etree.write(str(dst), method='html', encoding='utf-8')

Convert HtmlElement to str and vice versa howto

def s2e(s):
    return html.fragment_fromstring(s)

def e2s(e):
    return html.tostring(e, encoding='unicode')