 <p>Thought I should reword my answer.</p> <p>The built-in massages are good for light damage (extra whitespace, no closing slashes, etc). I would certainly try and get away with these before getting any more involved.</p> <p>You can <a href="http://www.crummy.com/software/BeautifulSoup/documentation.html#Sanitizing%20Bad%20Data%20with%20Regexps" rel="nofollow noreferrer">pass in your own massages</a> and I would suggest you extend the default set:</p> <pre><code>import copy, re myMassage = [(re.compile('&lt;!-([^-])'), lambda match: '&lt;!--' + match.group(1))] myNewMassage = copy.copy(BeautifulSoup.MARKUP_MASSAGE) myNewMassage.extend(myMassage) BeautifulSoup(badString, markupMassage=myNewMassage) # Foo&lt;!--This comment is malformed.--&gt;Bar&lt;br /&gt;Baz </code></pre> <p>You're probably better off doing it this way as it all goes into one parsing pot, gaining BeautifulSoups optimisations... Although the runtime performance is probably pretty similar.</p>