【发布时间】:2016-08-20 23:53:09
【问题描述】:
我正在使用 python3 进行一些网络抓取。我想保存网页并使用以下代码将其转换为文本:
import urllib
import html2text
url='http://www.google.com'
page = urllib.request.urlopen(url)
html_content = page.read()
rendered_content = html2text.html2text(html_content)
但是当我运行代码时,它报告了一个类型错误:
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/html2text-2016.4.2-py3.4.egg/html2text/__init__.py", line 127, in feed
data = data.replace("</' + 'script>", "</ignore>")
TypeError: 'str' does not support the buffer interface
谁能告诉我如何处理这个错误?提前谢谢!
【问题讨论】:
-
page.read().encode('utf-8')?
-
感谢您回答我的问题!我试过了,但它显示 AttributeError: 'bytes' object has no attribute 'encode'...
-
对不起,应该解码。
标签: python python-3.x web-scraping typeerror