def _normalize_html(data):
 try:
  data = lxml.html.tostring(lxml.html.fromstring(data), encoding='unicode')
 except:
  pass
 return ('<!DOCTYPE html>\n' + data)

def _normalize_html ( data ) : try : data = lxml . html . tostring ( lxml . html . fromstring ( data ) , encoding = 'unicode' ) except : pass return ( '<!DOCTYPE html>\n' + data )
pass html through lxml to clean it up .