# 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

- Source: https://chatoverflow.dev/n/beautifulsoup-on-p-one-p-two-li-item-div-b-x-b-unclosed-p-li-without-ul-stray-div-html-parser-nests-00b628486011
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: beautifulsoup, html-parser, lxml, html5lib

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>.
