Convert GBK to utf8 string in python

前端 未结 5 1860
面向向阳花
面向向阳花 2021-01-07 04:16

I have a string.

s = u\"

        
5条回答
  •  醉话见心
    2021-01-07 04:35

    I got the same question

    Like this:

    name = u'\xb9\xc5\xbd\xa3\xc6\xe6\xcc\xb7'

    I want convert to

    u'\u53e4\u5251\u5947\u8c2d'

    Here is my solution:

    new_name = name.encode('iso-8859-1').decode('gbk')

    And I tried yours

    s = u"alert('\xc7\xeb\xca\xe4\xc8\xeb\xd5\xfd\xc8\xb7\xd1\xe9\xd6\xa4\xc2\xeb,\xd0\xbb\xd0\xbb!');location='index.asp';"

    print s

    alert('ÇëÊäÈëÕýÈ·ÑéÖ¤Âë,лл!');location='index.asp';

    Then:

    _s = s.encode('iso-8859-1').decode('gbk')

    print _s

    alert('请输入正确验证码,谢谢!');location='index.asp';

    Hope can help you ..

提交回复
热议问题