我的代码只是爬取一个网页,然后将其转换为Unicode编码。
html = urllib.urlopen(link).read()
html.encode("utf8","ignore")
self.response.out.write(html)
但是我收到了一个UnicodeDecodeError错误:
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 507, in __call__
handler.get(*groups)
File "/Users/greg/clounce/main.py", line 55, in get
html.encode("utf8","ignore")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 2818: ordinal not in range(128)
我猜这意味着HTML中包含一些错误的Unicode尝试。我能否只删除导致问题的代码字节而不是得到错误?
c2
字节,否则可能会出现解码错误:http://hexutf8.com/?q=C2A0 - jar\x1b[38;5;226m...
的文本的人,这是ansi转义码,而不是Unicode。 - SurpriseDog