'ASCII'编解码器无法解码位置32817中的字节0xc2:序数不在范围内(128)

时间:2018-02-07 18:44:49

标签: python html css

我正在尝试从我的学校网站获取课程数据并将其解析为.json文件。我坚持输入代码:

import urllib.request

with urllib.request.urlopen('https://catalogue.ualberta.ca/') as response:
html = response.read()

decoded = html.decode('ascii')

当我运行它时,它给了我

'ASCII' codec can't decode byte 0xc2 in position 32817: ordinal not in range(128)

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

如果没有导致问题的输入,你很难做得很好,但效果很明显。 ASCII是7位代码,序号范围是0-127。最大值为0x7f;你超越了那个。我怀疑你需要的是Unicode,而不是ASCII。请参阅documentation

decoded = html.decode('utf-8')