python - help with coding issues
高洛峰
高洛峰 2017-05-27 17:39:46
0
2
697

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

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
阿神

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)

某草草

You can just use json to decode it directly

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template