python3 unicode列表转换为中文

查了很多很多的资料无果,果然知乎牛逼,知乎,完美解决。
爬取网站时,最终得到list内容,编码为unicode,想让其转换为汉字并输出。
需要提取的为下图中unicode部分:
在这里插入图片描述
保存为列表,然后使用for循环:
text为获取的网页。

pat = '"group": {"text": "(.*?)"'
text_list = re.compile(pat).findall(text)
for i in text_list:
    print(i.encode('latin-1').decode('unicode_escape')

输出结果为:
在这里插入图片描述
真是python3的unicode是方便了很多,但是遇到直接返回unicode字符串的想转换成中文真是坑爹,摸索半天不能用,原来还是要转码,给同样问题的道友点赞
转载:https://blog.csdn.net/wangxingfan316/article/details/79293914

猜你喜欢

转载自blog.csdn.net/weixin_40539892/article/details/88947721