search

Home  >  Q&A  >  body text

python - help with coding issues

The content I got when crawling was like this b{"title":"u5173u6ce8","card_type_name":"u5173u6ce8"}, please tell me how to convert the encoding into Chinese characters
I found a method first follow_text = follow.text.encode('utf-8').decode('unicode-escape'),
The first response can be converted like this, but follow.text conversion will result in 'utf-8' codec can' t encode characters in position 2809-2810,
Then try to change it to text[:2809], no error will be reported, but there is still an error if you change it to text[2811:]
Use print(follow.text[2800:2810] )The output is '_image_url', I don’t know why the conversion failed
I would like to ask what the problem is, or is there any other way to convert the content I got

高洛峰高洛峰2781 days ago725

reply all(2)I'll reply

  • 阿神

    阿神2017-05-27 17:41:46

    If follow.text本身是 str(unicode) 的话,encode('utf8') 回去没有任何意义,直接 decode('unicode-escape') that’s fine

    If follow.text是 bytes 的话,那就可以选择先 decode('utf8') ,再 decode('unicode-escape')

    (assuming the correct encoding in your question is utf8)

    reply
    0
  • 某草草

    某草草2017-05-27 17:41:46

    You can just use json to decode it directly

    reply
    0
  • Cancelreply