<分区>
我正在尝试通过一个大胆的类(class)在 python 中制作一个爬虫。我有这个方法 get_page()
返回页面的内容。
def get_page(url):
'''
Open the given url and return the content of the page.
'''
data = urlopen(url)
html = data.read()
return html.decode('utf8')
原来的方法只是返回data.read()
,但是那样我就不能做像str.find()
这样的操作了。快速搜索后,我发现我需要解码数据。但是现在我得到了这个错误
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
我在 SO 中发现了类似的问题,但没有一个是专门针对此的。请帮忙。