Python 爬虫解码问题解决

import urllib
response = urllib.request.urlopen('http://math.sysu.edu.cn/main/default/index.aspx')
html = response.read()
html = html.decode('utf-8')
print(html)

上述代码会出现如下错误:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd6 in position 396: invalid continuation byte 

问题是解码错误

只需将 html = html.decode('utf-8') 换成 html = html.decode('gbk') 即可

    原文作者:子辰曦
    原文地址: https://blog.csdn.net/u012675539/article/details/47024309
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞