编码转换
本帖最后由 Zzxy 于 2024-3-24 11:00 编辑我给companyTags(公司福利)和workTags这样定义的:workTag = json.dumps(list(map(lambda x:x.text,workTag))) companyTags = json.dumps(companyTags.split(','))
它抓取到的数据分别是workTag:[""\u524d\u7aef\u5f00\u53d1"", ""HTML5"", ""JQuery"", ""Vue.js""]"companyTags:[""\u8282\u65e5\u793c\u54c1\uff0c\u5e74\u5ea6\u4f53\u68c0\uff0c\u514d\u8d39\u5065\u8eab\u8bbe\u65bd\uff0c\u52a0\u73ed\u8865\u52a9\uff0c\u5305\u5403\uff0c\u8282\u5047\u65e5\u52a0\u73ed\u8d39\uff0c\u9910\u996e\u53ca\u4e0b\u5348\u8336\uff0c\u8282\u65e5\u798f\u5229\uff0c\u56e2\u5efa\u805a\u9910\uff0c\u96f6\u98df\u4e0b\u5348\u8336\uff0c\u5c31\u8fd1\u79df\u623f\u8865\u8d34\uff0c\u5f39\u6027\u5de5\u4f5c\u5236\uff0c\u6cd5\u5b9a\u8282\u5047\u65e5\u4e09\u85aa\uff0c\u8865\u5145\u533b\u7597\u4fdd\u9669\uff0c\u4e94\u9669\u4e00\u91d1\uff0c\u5e26\u85aa\u5e74\u5047\uff0c\u5bb6\u5ead\u5173\u7231\u5047\uff0c\u5b9a\u671f\u4f53\u68c0""]
爬取到的数据想变成汉字或者字母,这要怎么改?
已解决·改成了workTag = list(map(lambda x:x.text,workTag)) .encode('utf-8').decode() encoded_string = r'\u524d\u7aef\u5f00\u53d1'
decoded_string = bytes(encoded_string, 'utf-8').decode('unicode-escape')
print(decoded_string)# 输出:前端开发 dumps 的参数加上 ensure_ascii=False
参考文档 https://docs.python.org/zh-cn/3/library/json.html#json.dumps
如果你只需要 print 查看内容的话,不需要提前调用 json.dumps 来序列化对象到字符串。 这好像是unicode吧
页:
[1]