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')
即可