类型错误:需要一个类似字节的对象,而不是“ str”-html2text

时间:2019-01-11 17:38:48

标签: python-3.x

我正在尝试使用python,并尝试将网页数据复制到文本文件中,并在其中出现以下python错误

import html2text
url=''
page = urllib.request.urlopen(url)
html_content = page.read()
rendered_content = html2text.html2text(html_content)

请参阅以下错误。

rendered_content = html2text.html2text(html_content)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python36\lib\site-packages\html2text\__init__.py", line 937, in html2text
    return h.handle(html)
  File "C:\Program Files\Python36\lib\site-packages\html2text\__init__.py", line 149, in handle
    self.feed(data)
  File "C:\Program Files\Python36\lib\site-packages\html2text\__init__.py", line 145, in feed
    data = data.replace("</' + 'script>", "</ignore>")
TypeError: a bytes-like object is required, not 'str'

    rendered_content = html2text.html2text(html_content)
  File "<stdin>", line 1
    rendered_content = html2text.html2text(html_content)
     ^

0 个答案:

没有答案