Validate (X)HTML in Python
<p>What's the best way to go about validating that a document follows some version of HTML (prefereably that I can specify)? I'd like to be able to know where the failures occur, as in a web-based validator, except in a native Python app.</p>

<p><a href="http://countergram.com/software/pytidylib">http://countergram.com/software/pytidylib</a> is a nice python binding for HTML Tidy.  Their example:</p>

<pre><code>from tidylib import tidy_document
document, errors = tidy_document('''&lt;p&gt;f&amp;otilde;o &lt;img src="bar.jpg"&gt;''',
    options={'numeric-entities':1})
print document
print errors
</code></pre>
