# coding=utf-8 def dec(a): # &#x 开头 解码 : 以 &# 或 &#x 开头的字符串叫做 NCR 字符 # 通过 py2.x下的HTMLParser 或 py3.x下的html 的 unescape() 方法来转换成能看懂的中文字符 aa = a.replace(';', '').replace('&#x', '\\u').encode('utf-8').decode('unicode_escape') print(aa) return aa def dec_r(b): # r'\u4eba\u751f\u82e6\u77ed\uff0cpy\u662f\u5cb8' 开头 解码 # python3 以上 字符串不能 直接 decode, 先编码成utf-8 , 在进行解码 bb = b.encode('utf-8').decode('unicode_escape') print(bb) return bb if __name__ == '__main__': ''' 编码 解码 ''' a = '【试呼】' # 【试呼】 a = 'http://www.6688.appsvipapi.kuuhui.com:65533/plje/id.php ' # http://www.6688.appsvipapi.kuuhui.com:65533/plje/id.php # dec(a) # &#x 开头 解码 b = u'\u4eba\u751f\u82e6\u77ed\uff0cpy\u662f\u5cb8' # 直接打印出来 ————》 人生苦短,py是岸 b = r'\u4eba\u751f\u82e6\u77ed\uff0cpy\u662f\u5cb8' dec_r(b)
python3 NCR 字符解码
猜你喜欢
转载自blog.csdn.net/l1159015838/article/details/81126834
今日推荐
周排行