Python crawled to the page source code has a similar u51a0u7434, how to convert to Chinese?

Source: Internet
Author: User
Tags array to string
Python crawled to the page source code has a similar \u51a0\u7434, how to convert to Chinese?

Reply content:

Found a library called AST, there is a function, called Literal_eval.
Xie invited, more familiar with the standard library (7.8. Codecs ) Bar:
>>> s = r'\u51a0\u7434'>>> print s\u51a0\u7434>>> s.decode('unicode_escape')u'\u51a0\u7434'>>> print s.decode('unicode_escape')冠琴
2014-11-25
After looking at the wheel brother's answer, think of Python 3.x provides the Ord and CHR two built-in functions. Implements the conversion between Unicode code point and characters.
ongoing-study/ucps.py at Master Myd7349/ongoing-study GitHub
There is no Python 2 handy. Orz
2015-06-03
The content of the previous answer is misleading! I am sorry.
How to get Unicode code in Chinese in Python3? -Myd7349 's answer
----

' u\u51a0\u7434 ' is not U ' \u51a0\u7434 ', the Lord himself does not understand the meaning of the things he searched, @ Liu Xiang also do not know what the main question (found after the hint has already known the main question asked what). This 51a0 and 7434 represent 16 binary 4 bytes, which is Unicode encoding, Python certainly has to provide numbers to character or byte array to string function, you have to process them into numbers, and then go.

Javascript:
this is actually This is actually UnicodeCode. Unicode uses a 16-bit integer to represent any character that exists in the world, that is, any character that can be displayed corresponds to an integer in Unicode.
This notation is an escape notation for Unicode characters, followed by \u with the word corresponding to the Unicode integer. hexadecimalnotation to represent a Unicode character.

More than just Python, a large number of programming languages use two-byte Unicode as the basic character type。 such as Java and JavaScript.
There are a number of tools that can help you convert text to Unicode. For example: 16 characters コードin javaユニコード
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.