在Python中將Unicode轉換為ASCII而沒有錯誤我的代碼只是抓取一個網頁,然后將其轉換為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嘗試。我可以刪除導致問題的任何代碼字節而不是出錯嗎?
添加回答
舉報
0/150
提交
取消