I have lists with element
[u'\xd0\xbc\xd1\x82\xd1\x81 \xd0\xbe\xd1\x84\xd0\xb8\xd1\x86\xd0\xb8\xd0\xb0\xd0\xbb\xd1\x8c\xd0\xbd\xd1\x8b\xd0\xb9 \xd1\x81\xd0\xb0\xd0\xb9\xd1\x82']
[u'\xd0\xbc\xd1\x82\xd1\x81 \xd0\xbe\xd1\x84\xd0\xb8\xd1\x86\xd0\xb8\xd0\xb0\xd0\xbb\xd1\x8c\xd0\xbd\xd1\x8b\xd0\xb9 \xd1\x81\xd0\xb0\xd0\xb9\xd1\x82']
I try to convert it using
val[0].encode('utf-8')
And got after it
мÑÑ Ð¾ÑиÑиалÑнÑй ÑайÑ
мÑÑ Ð¾ÑиÑиалÑнÑй ÑайÑ
What I do wrong?
You have a Mojibake; text decoded using the wrong codec.
You have what looks like it was decoded or Latin-1 or Windows codepage 1252, while it should have been decoded as UTF-8 instead.
Either reverse the encoding manually, or use the excellent ftfy
package to do it for you:
>>> import ftfy
>>> data = [u'\xd0\xbc\xd1\x82\xd1\x81 \xd0\xbe\xd1\x84\xd0\xb8\xd1\x86\xd0\xb8\xd0\xb0\xd0\xbb\xd1\x8c\xd0\xbd\xd1\x8b\xd0\xb9 \xd1\x81\xd0\xb0\xd0\xb9\xd1\x82']
>>> ftfy.ftfy(data[0])
u'\u043c\u0442\u0441 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0430\u0439\u0442'
>>> print ftfy.ftfy(data[0])
мтс официальный сайт
Manually, you'd re-encode as Latin-1:
>>> data[0].encode('latin1')
'\xd0\xbc\xd1\x82\xd1\x81 \xd0\xbe\xd1\x84\xd0\xb8\xd1\x86\xd0\xb8\xd0\xb0\xd0\xbb\xd1\x8c\xd0\xbd\xd1\x8b\xd0\xb9 \xd1\x81\xd0\xb0\xd0\xb9\xd1\x82'
>>> data[0].encode('latin1').decode('utf8')
u'\u043c\u0442\u0441 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0430\u0439\u0442'
>>> print data[0].encode('latin1').decode('utf8')
мтс официальный сайт
Note that you have a list with one unicode
object in it. You may want to study up on Python and Unicode; I recommend the following documents:
Pragmatic Unicode by Ned Batchelder
The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) by Joel Spolsky
These will help you understand when to encode and when to decode, and what codec to use.