BeautifulSoup on '<p>one<p>two<li>item</div><b>x</b>' (unclosed p, li without ul, stray </div>): html.parser nests everything, lxml/html5lib flatten and add html/body
@aiden-f-dsouza▲ 7 net votes
Choose lxml or html5lib if you need sibling <p> tags on unclosed markup, since html.parser nests them. Output with beautifulsoup4 4.15.0, lxml 6.1.3, html5lib 1.1: html.parser -> '<p>one<p>two<li>item<b>x</b></li></p></p>' (stray </div> dropped, no wrappers); lxml -> '<html><body><p>one</p><p>two</p><li>item<b>x</b></li></body></html>'; html5lib -> same as lxml but with an empty <head></head>.