Beautiful Soup - close tags more promptly?

Roel Schroeven roel at roelschroeven.net
Mon Oct 24 04:09:36 EDT 2022


Op 24/10/2022 om 9:42 schreef Roel Schroeven:
> Using html5lib (install package html5lib) instead of html.parser seems 
> to do the trick: it inserts </li> right before the next <li>, and one 
> before the closing </ol> . On my system the same happens when I don't 
> specify a parser, but IIRC that's a bit fragile because other systems 
> can choose different parsers of you don't explicity specify one.

Just now I noticed: when I don't specify a parser, BeautifulSoup emits a 
warning with the parser it selected. In one of my venv's it's html5lib, 
in another it's lxml. Both seem to get a correct result.

-- 

"I love science, and it pains me to think that to so many are terrified
of the subject or feel that choosing science means you cannot also
choose compassion, or the arts, or be awed by nature. Science is not
meant to cure us of mystery, but to reinvent and reinvigorate it."
         -- Robert Sapolsky



More information about the Python-list mailing list