title: Gibberish text output because of encoding in web scraping
body: <p>I'm trying to get a text in Persian language from Google Translate, and the best encoding type for Persian is UTF-8.</p>
  <p>Google Translate uses Javascript to render its HTML codes, so I'm using <code>html-requests</code> module for this.</p>
  <p>What I have problem with is the output that I get each time, both either when I use <code>print()</code> or when I try to write it into a file. Both ways will give me a gibberish non-Persian text, and I know it's because of the encoding or something like this.</p>
  <p>So I was trying to change encoding to <code>utf-8</code> whenever I could, this my code:</p>
  <pre><code>import requests_html
  from bs4 import BeautifulSoup as BS
  
  url = &quot;https://translate.google.com/#view=home&amp;op=translate&amp;sl=en&amp;tl=hy&amp;text={}&quot;
  text = input(&quot;text: &quot;)
  
  session = requests_html.HTML(url=url.format(text), html='str')
  
  session.render() # for executing js scripts
  content = session.raw_html
              
  soup = BS(content, &quot;html.parser&quot;, from_encoding='utf-8')
  table_rows = soup.find(&quot;table&quot;, &quot;gt-baf-table&quot;).find_all('span')
  
  # this is my way for write the output into a file
  with open('file.txt', 'wb') as file:
      for table_row in table_rows:
          file.write(table_row.text.encode('utf-8'))
  </code></pre>
  <p>This is the output I got for word <strong>space</strong>:</p>
  <pre><code>nounտարածությունտարածությունspacedistanceareaspreadroomtractծավալծավալvolumesizemagnitudebulkspacecontentնստելատեղնստելատեղsiegespaceհեռավորությունհեռավորությունdistancelengthspaceintervalwayտևողությունտևողությունspacestanding
  </code></pre>
  <p><strong>Note:</strong> I tried to write all of the HTML codes that I got from <code>session.raw_html</code> and into a file, then search for that Persian texts in HTML code, but that resulted in the same as the above output, I got gibberish and nonsense text.</p>