using beautifulsoup with html5lib, it puts the html, head and body tags automatically:
BeautifulSoup(\'FOO\', \'html5lib\') # => <
If you want it to look better, try this:
BeautifulSoup([contents you want to analyze].prettify())