title: Python3 html and lxml parser encoding problem
body: <p>When parsing some HTML using <code>BeautifulSoup</code> or <code>PyQuery</code>, they will use a parser  like <code>lxml</code> or <code>html5lib</code>. Let's say I've a file containing the following</p>
  
  <pre><code>&lt;span&gt;  é    and    ’  &lt;/span&gt;
  </code></pre>
  
  <p>In my environnement they seems incorrectly encoded, using <code>PyQuery</code>:</p>
  
  <pre><code>&gt;&gt;&gt; doc = pq(filename=PATH, parser="xml")
  &gt;&gt;&gt; doc.text()
  'Ã© and â\u20ac\u2122'
  &gt;&gt;&gt; doc = pq(filename=PATH, parser="html")
  &gt;&gt;&gt; doc.text()
  'Ã\x83Â© and Ã¢â\x82¬â\x84¢'
  &gt;&gt;&gt; doc = pq(filename=PATH, parser="soup")
  &gt;&gt;&gt; doc.text()
  'Ã© and â\u20ac\u2122'
  &gt;&gt;&gt; doc = pq(filename=PATH, parser="html5")
  &gt;&gt;&gt; doc.text()
  'Ã© and â\u20ac\u2122'
  </code></pre>
  
  <p>Beyond the fact that the encoding seems incorrect, one of the main problem is that <code>doc.text()</code> returns an instance of <code>str</code> instead of <code>bytes</code> which isn't a normal thing according to <a href="https://stackoverflow.com/questions/52123701/python3-how-to-encode-this-string-correctly">that question</a> I asked yesterday.</p>
  
  <p>Also, passing the argument <code>encoding='utf-8'</code> to <code>PyQuery</code> seems useless, I tried <code>'latin1'</code> nothing change. I also tried to add some meta data because I read that <code>lxml</code> read them to figure out what encoding to use but it doesn't change anything:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="fr" dir="ltr"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="content-type" content="text/html;charset=latin1"/&gt;
  &lt;span&gt;  é    and    ’  &lt;/span&gt;
  &lt;/head&gt;
  &lt;/html&gt;  
  </code></pre>
  
  <p>If I use <code>lxml</code> directly it seems a bit different</p>
  
  <pre><code>&gt;&gt;&gt; from lxml import etree
  &gt;&gt;&gt; tree = etree.parse(PATH)
  &gt;&gt;&gt; tree.docinfo.encoding
  'UTF-8'
  
  &gt;&gt;&gt; result = etree.tostring(tree.getroot(), pretty_print=False)
  &gt;&gt;&gt; result
  b'&lt;span&gt;  &amp;#233;    and    &amp;#8217;  &lt;/span&gt;'
  
  &gt;&gt;&gt; import html
  &gt;&gt;&gt; html.unescape(result.decode('utf-8'))
  '&lt;span&gt;  é    and    \u2019  &lt;/span&gt;\n'
  </code></pre>
  
  <p>Erf, It drives me a bit crazy, your help would be appreciated</p>