G
G
ghostku2015-11-09 00:25:10
Python
ghostku, 2015-11-09 00:25:10

How to convert unicode sequences to readable characters?

There is a line like "\u0421\u0438\u043d\u0438\u0439". How to get the string "Blue" from it?
Thanks
UPD: I'll ask the question differently:
There is a real piece of code

import urllib.request, lxml.html as html
src = urllib.request.urlopen("http://ekopups.ua/detskie-pelenki")
encod=src.headers.get_content_charset()
if encod==None: encod="cp1251"
print (encod)
src = src.read()
#.decode(encod)
print (src)
src = html.document_fromstring(src)
res=src.xpath(".//div[@class='title-feedback']/text()")
print (res)

The output is a string containing characters of the form \\u0440 and \xd1 What needs to be changed in the existing code (and in what place) so that instead of these characters the output contains readable characters.
Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2015-11-09
@sim3x

print u'\u0421\u0438\u043d\u0438\u0439'

V
Vov Vov, 2015-11-09
@balamut108

u''.encode('raw-unicode-escape')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question