赞
踩
chinese = "你好"
re = chinese.encode("unicode_escape")
print(re)
返回:b'\\u4f60\\u597d'
unicode = b'\\u4f60\\u597d'
re = unicode.decode("unicode_escape")
print(re)
返回:你好
unicode = '\\u4f60\\u597d'
re = unicode.encode('utf-8').decode('unicode_escape')
print(re)
返回:你好
遇到Unicode是通过requests在网上爬取的时候,你也可以这样
response = requests.post(url,headers=headers)
print(response.text.encode('utf-8').decode('unicode_escape'))
方法三可能有报错,还可以这样
response = requests.get(url,headers=headers)
re = eval("u"+"\'"+response.text+"\'")
print(re)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。