WHCSRL 技术网

【python ascii码转中文】1分钟教你编码转换

核心:

ascii 转中文
print(name.encode().decode('unicode_escape'))
  • 1
  • 2

一开始发起请求:

information = requests.get(information_url,headers=header).text
print(information)
  • 1
  • 2

出现乱码,经过查看发现是ascii 码

information信息如下:

jQuery191040122200903040794_1635653294983({"status":1,"err_code":0,"data":{"hash":"B18D453224097D52798F88399210A2AF","timelength":310000,"filesize":4964723,"audio_name":"u6d77u6765u963fu6728 - u4e94u5341u5e74u4ee5u540e","have_album":1,"album_name":"u4e94u5341u5e74u4ee5u540e","album_id":"47771132","img":"http://imge.kugou.com/stdmusic/20210809/20210809163049244073.jpg","have_mv":1,"video_id":"5102419","author_name":"u6d77u6765u963fu6728","song_name":"u4e94u5341u5e74u4ee5u540e","lyrics":"ufeff[id:$00000000]
[ar:u6d77u6765u963fu6728]
[ti:u4e94u5341u5e74u4ee5u540e]
[by:]
[hash:b18d453224097d52798f88399210a2af]
[al:]
[sign:]
[qq:]
[total:310256]
[offset:0]
[00:00.61]u6d77u6765u963fu6728 - u4e94u5341u5e74u4ee5u540e
[00:01.42]u4f5cu8bcduff1au9ad8u5dddu4e1c
[00:01.57]u4f5cu66f2uff1au9ad8u5dddu4e1c
[00:01.72]u7f16u66f2uff1au6587u514bu6d25
[00:01.93]u5f55u97f3uff1au66f2u6bd4u963fu4e14
[00:02.13]u6df7u97f3uff1au5f20u9eceu5175
[00:02.28]u63a8u5e7fuff1au661fu6597u63a8
[00:02.28]OPuff1au575au8bdau6587u5316
[00:02.43](u672au7ecfu8457u4f5cu6743u4ebau8bb8u53efuff0cu4e0du5f97u7ffbu5531u3001u7ffbu5f55u6216u4f7fu7528)
[00:28.51]u6b64u751fu6700u597du7684u8fd0u6c14
[00:32.04]u5c31u662fu9047u89c1u4e86u4f60
[00:35.37]u521au597du4f60u4e5fu7231u6211
[00:38.96]u6211u4e5fu7231u7740u4f60
[00:41.63]u5728u8fd9u4e2au5c34u5c2cu5e74u7eaa
[00:44.86]u6211u4e0du518du662fu4e00u4e2au4eba
[00:48.54]u591au5e78u8fd0u80fdu548cu4f60u5728u4e00u8d77
[00:54.61]u6b64u751fu6700u5927u7684u6b22u559c
[00:58.04]u5c31u662fu7b49u5230u4e86u4f60
[01:01.67]u662fu4f60u5e26u6211u8d70u51fa
[01:05.35]u90a3u7247u6cbcu6cfdu5730
[01:07.92]u4eceu6211u4eecu4ea4u6362u4fe1u7269
[01:11.10]u6df1u60c5u76f8u671bu90a3u523bu8d77
[01:14.79]u6211u7684u4f59u751fu5c31u662fu4f60
[01:21.00]u6211u5e0cu671bu4e94u5341u5e74u4ee5u540e
[01:24.43]u4f60u8fd8u80fdu5728u6211u5de6u53f3
[01:27.97]u548cu4f60u5750u5728u6447u6905u91cc
[01:30.79]u611fu53d7u90a3u5915u9633u7684u6e29u67d4
[01:34.58]u542cu5faeu98ceu8f7bu8f7bu5730u5439
[01:37.72]u542cu6cb3u6c34u6162u6162u5730u6d41
[01:41.55]u518du804au804au4eceu524du65e5u5b50
[01:44.31]u521au8c08u604bu7231u7684u65f6u5019
[01:50.63]u6211u5e0cu671bu4e94u5341u5e74u4ee5u540e
[01:54.22]u4f60u8fd8u80fdu5728u6211u5de6u53f3
[01:57.60]u90a3u65f6u90fdu5df2u767du4e86u5934
[02:00.58]u8fd8u60f3u542cu4f60u53ebu6211u4e2bu5934
[02:04.07]u8f7bu8f7bu7275u7740u4f60u7684u624b
[02:07.35]u9759u9759u9760u5728u4f60u80f8u53e3
[02:11.09]u8fd9u4e2au753bu9762
[02:12.41]u662fu4e0du662fu5c31u53ebu505au957fu76f8u53aeu5b88
[02:46.69]u6b64u751fu6700u5927u7684u6b22u559c
[02:50.02]u5c31u662fu7b49u5230u4e86u4f60
[02:53.56]u662fu4f60u5e26u6211u8d70u51fa
[02:57.10]u90a3u7247u6cbcu6cfdu5730
[02:59.78]u4eceu6211u4eecu4ea4u6362u4fe1u7269
[03:02.91]u6df1u60c5u76f8u671bu90a3u523bu8d77
[03:06.59]u6211u7684u4f59u751fu5c31u662fu4f60
[03:13.00]u6211u5e0cu671bu4e94u5341u5e74u4ee5u540e
[03:16.23]u4f60u8fd8u80fdu5728u6211u5de6u53f3
[03:19.82]u548cu4f60u5750u5728u6447u6905u91cc
[03:22.55]u611fu53d7u90a3u5915u9633u7684u6e29u67d4
[03:26.34]u542cu5faeu98ceu8f7bu8f7bu5730u5439
[03:29.52]u542cu6cb3u6c34u6162u6162u5730u6d41
[03:33.26]u518du804au804au4eceu524du65e5u5b50
[03:36.08]u521au8c08u604bu7231u7684u65f6u5019
[03:42.24]u6211u5e0cu671bu4e94u5341u5e74u4ee5u540e
[03:45.93]u4f60u8fd8u80fdu5728u6211u5de6u53f3
[03:49.31]u90a3u65f6u90fdu5df2u767du4e86u5934
[03:52.29]u8fd8u60f3u542cu4f60u53ebu6211u4e2bu5934
[03:55.87]u8f7bu8f7bu7275u7740u4f60u7684u624b
[03:59.16]u9759u9759u9760u5728u4f60u80f8u53e3
[04:02.89]u8fd9u4e2au753bu9762
[04:04.15]u662fu4e0du662fu5c31u53ebu505au957fu76f8u53aeu5b88
[04:15.52]u6211u5e0cu671bu4e94u5341u5e74u4ee5u540e
[04:18.91]u4f60u8fd8u80fdu5728u6211u5de6u53f3
[04:22.10]u90a3u65f6u90fdu5df2u767du4e86u5934
[04:25.28]u8fd8u60f3u542cu4f60u53ebu6211u4e2bu5934
[04:28.86]u8f7bu8f7bu7275u7740u4f60u7684u624b
[04:32.09]u9759u9759u9760u5728u4f60u80f8u53e3
[04:35.84]u8fd9u4e2au753bu9762
[04:37.10]u662fu4e0du662fu5c31u53ebu505au957fu76f8u53aeu5b88
","author_id":"548441","privilege":8,"privilege2":"1000","play_url":"https://webfs.tx.kugou.com/202111011207/e7877963efb3e68330176fb5b314a001/KGTX/CLTX001/b18d453224097d52798f88399210a2af.mp3","authors":[{"author_id":"548441","author_name":"u6d77u6765u963fu6728","is_publish":"1","sizable_avatar":"http://singerimg.kugou.com/uploadpic/softhead/{size}/20210525/20210525110634207124.jpg","avatar":"http://singerimg.kugou.com/uploadpic/softhead/400/20210525/20210525110634207124.jpg"}],"is_free_part":0,"bitrate":128,"recommend_album_id":"47771132","audio_id":"116180496","has_privilege":true,"play_backup_url":"https://webfs.cloud.kugou.com/202111011207/9460ee5d4aaebc7c61029bd7a32d9c49/KGTX/CLTX001/b18d453224097d52798f88399210a2af.mp3"}});

  • 1
  • 2

如何将上面的ascii码信息转换为中文呢?

# ascii 转中文
print(information.encode().decode('unicode_escape'))
  • 1
  • 2

再次运行查看结果如下,成功出现了中文。

jQuery191040122200903040794_1635653294983({"status":1,"err_code":0,"data":{"hash":"B18D453224097D52798F88399210A2AF","timelength":310000,"filesize":4964723,"audio_name":"海来阿木 - 五十年以后","have_album":1,"album_name":"五十年以后","album_id":"47771132","img":"http://imge.kugou.com/stdmusic/20210809/20210809163049244073.jpg","have_mv":1,"video_id":"5102419","author_name":"海来阿木","song_name":"五十年以后","lyrics":"[id:$00000000]
[ar:海来阿木]
[ti:五十年以后]
[by:]
[hash:b18d453224097d52798f88399210a2af]
[al:]
[sign:]
[qq:]
[total:310256]
[offset:0]
[00:00.61]海来阿木 - 五十年以后
[00:01.42]作词:高川东
[00:01.57]作曲:高川东
[00:01.72]编曲:文克津
[00:01.93]录音:曲比阿且
[00:02.13]混音:张黎兵
[00:02.28]推广:星斗推
[00:02.28]OP:坚诚文化
[00:02.43](未经著作权人许可,不得翻唱、翻录或使用)
[00:28.51]此生最好的运气
[00:32.04]就是遇见了你
[00:35.37]刚好你也爱我
[00:38.96]我也爱着你
[00:41.63]在这个尴尬年纪
[00:44.86]我不再是一个人
[00:48.54]多幸运能和你在一起
[00:54.61]此生最大的欢喜
[00:58.04]就是等到了你
[01:01.67]是你带我走出
[01:05.35]那片沼泽地
[01:07.92]从我们交换信物
[01:11.10]深情相望那刻起
[01:14.79]我的余生就是你
[01:21.00]我希望五十年以后
[01:24.43]你还能在我左右
[01:27.97]和你坐在摇椅里
[01:30.79]感受那夕阳的温柔
[01:34.58]听微风轻轻地吹
[01:37.72]听河水慢慢地流
[01:41.55]再聊聊从前日子
[01:44.31]刚谈恋爱的时候
[01:50.63]我希望五十年以后
[01:54.22]你还能在我左右
[01:57.60]那时都已白了头
[02:00.58]还想听你叫我丫头
[02:04.07]轻轻牵着你的手
[02:07.35]静静靠在你胸口
[02:11.09]这个画面
[02:12.41]是不是就叫做长相厮守
[02:46.69]此生最大的欢喜
[02:50.02]就是等到了你
[02:53.56]是你带我走出
[02:57.10]那片沼泽地
[02:59.78]从我们交换信物
[03:02.91]深情相望那刻起
[03:06.59]我的余生就是你
[03:13.00]我希望五十年以后
[03:16.23]你还能在我左右
[03:19.82]和你坐在摇椅里
[03:22.55]感受那夕阳的温柔
[03:26.34]听微风轻轻地吹
[03:29.52]听河水慢慢地流
[03:33.26]再聊聊从前日子
[03:36.08]刚谈恋爱的时候
[03:42.24]我希望五十年以后
[03:45.93]你还能在我左右
[03:49.31]那时都已白了头
[03:52.29]还想听你叫我丫头
[03:55.87]轻轻牵着你的手
[03:59.16]静静靠在你胸口
[04:02.89]这个画面
[04:04.15]是不是就叫做长相厮守
[04:15.52]我希望五十年以后
[04:18.91]你还能在我左右
[04:22.10]那时都已白了头
[04:25.28]还想听你叫我丫头
[04:28.86]轻轻牵着你的手
[04:32.09]静静靠在你胸口
[04:35.84]这个画面
[04:37.10]是不是就叫做长相厮守
","author_id":"548441","privilege":8,"privilege2":"1000","play_url":"https://webfs.ali.kugou.com/202111011212/31a50f724f552c4b8136d81c92907244/KGTX/CLTX001/b18d453224097d52798f88399210a2af.mp3","authors":[{"author_id":"548441","author_name":"海来阿木","is_publish":"1","sizable_avatar":"http://singerimg.kugou.com/uploadpic/softhead/{size}/20210525/20210525110634207124.jpg","avatar":"http://singerimg.kugou.com/uploadpic/softhead/400/20210525/20210525110634207124.jpg"}],"is_free_part":0,"bitrate":128,"recommend_album_id":"47771132","audio_id":"116180496","has_privilege":true,"play_backup_url":"https://webfs.cloud.kugou.com/202111011212/fff38e75bbe712ffc09e6f2a74841e54/KGTX/CLTX001/b18d453224097d52798f88399210a2af.mp3"}});

Process finished with exit code 0

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
推荐阅读