Python爬虫類の復号問題は解決します。

577 ワード

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')に両替すればいいです。