有日语的阅读网站
UnicodeDecodeCharacter 'ascii' cocec 无法解码位置 348 处的字节 0xe3:序号不在范围(128)
我有 urllib.urlopen
-ing 一个网站,并且我有一个.readlines()
逐段浏览它,搜索某些文本。
我从一个网站上阅读,上面有一些日语字符(我想跳过这一部分),但是我的代码在读取它时崩溃了。
或者更简单地说,我可以将整个 urllib.urlopen
转换为 unicode,这样我就不会收到此 ASCII 错误,如果是这样,我该如何搜索它?
UnicodeDecodeCharacter 'ascii' cocec can't decode byte 0xe3 at position 348: ordinal not in range(128)
I have urllib.urlopen
-ing a website, and I have a .readlines()
going through it paragraph by paragraph, searching for certain text.
I reading from a website that has a few Japanese characters on it (I WANT TO SKIP THIS PART), but my code crashes when it reads over it.
Or on a simpler note, can I convert the entire urllib.urlopen
to a unicode so that I don't get this ASCII error, and if so, how do I search through it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以读取原始字节,将它们转换为 ascii(同时忽略非 ascii),然后分割行:
这段代码应该是您开始的。技术上更正确的方法包括读取标题或正文的前几行以找到正确的字符集,然后使用该字符集进行解码。
You can read in the raw bytes, convert them to ascii (while ignoring non-ascii) and then split the lines:
This code should be you started. The more technically correct way involves reading the headers or the first few lines of the body to find the correct charset and then decoding using that charset.