title: Using lxml.html with broken html entities?
body: <p>I need to work with a page, which has an unfortunate mix of correct and incorrect HTML entities; for instance:</p>
  
  <pre><code>&lt;i&gt;Kristj&amp;aacuten V&amp;iacute;ctor&lt;/i&gt;
  </code></pre>
  
  <p>This, in Firefox 67, does get interpreted correctly, eventually:</p>
  
  <p><a href="https://i.stack.imgur.com/xKZWR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xKZWR.png" alt="ff-htmlent1.png"></a></p>
  
  <p>... however, if we do "View Source", Firefox indicates via syntax color that something is wrong with the first HTML entity:</p>
  
  <p><a href="https://i.stack.imgur.com/kmKEt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kmKEt.png" alt="ff-htmlent2.png"></a></p>
  
  <p>... and indeed there is, a semicolon at the end of the HTML entity is missing - however, somehow Firefox figures it out, and renders the right character.</p>
  
  <p>Now, if I try to work with that in lxml:</p>
  
  <pre class="lang-python prettyprint-override"><code>#!/usr/bin/env python3
  
  import lxml.html as LH
  import lxml.html.clean as LHclean
  
  testhtmlstring = "&lt;i&gt;Kristj&amp;aacuten V&amp;iacute;ctor&lt;/i&gt;"
  
  myhtml = LH.fromstring( testhtmlstring )
  myhtml = LHclean.clean_html( myhtml )
  myitem = myhtml.xpath("//i")[0]
  myitemstr = myitem.text_content()
  print(myitemstr)
  </code></pre>
  
  <p>... the code prints out this in terminal (Ubuntu 18.04):</p>
  
  <pre><code>Kristj&amp;aacuten Víctor
  </code></pre>
  
  <p>... so, obviously, the broken htmlentity did not get converted to the right character.</p>
  
  <p>Is there something I can use, so I get the right character in my output string from lxml, even in case of a broken htmlentity (as Firefox does)?</p>