在 Python 中解码 UTF-8 字符串 [英] Decoding UTF-8 strings in Python

查看:49
本文介绍了在 Python 中解码 UTF-8 字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 python 编写一个网络爬虫,它涉及从网站上获取头条新闻.

I'm writing a web crawler in python, and it involves taking headlines from websites.

其中一个标题应该是:Hip 也来了

One of the headlines should've read : And the Hip's coming, too

但它却说:Hip 也来了

But instead it said: And the Hip’s coming, too

这里出了什么问题?

推荐答案

您需要正确解码源文本.源文本很可能是 UTF-8 格式,而不是 ASCII.

You need to properly decode the source text. Most likely the source text is in UTF-8 format, not ASCII.

因为您没有为您的问题提供任何上下文或代码,所以无法直接回答.

Because you do not provide any context or code for your question it is not possible to give a direct answer.

我建议你研究一下 Python 中是如何完成 unicode 和字符编码的:

I suggest you study how unicode and character encoding is done in Python:

http://docs.python.org/2/howto/unicode.html

这篇关于在 Python 中解码 UTF-8 字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆