【爬虫】编码问题总结

request返回的response出现乱码

直接出现乱码,是编码错误

res.encoding(encode)  # encode为指定的编码
print(res.text)

这是由于直接赋予的编码不对。

出现\u559c\u6b22\u4e00\u4e2a等类似的unicode编码

print(res.content.decode("unicode-escape"))

需要解析unicode编码

出现&#x884c等以&#x开头的

import html
print(html.unescape(res.text))

&#x开头的是一种网页编码格式需要通过html解析

posted @ 2019-03-30 11:29  丿小呆  阅读(364)  评论(0编辑  收藏  举报