requests请求报字符编码异常信息

requests请求报字符编码异常信息

原创

CorwinPC博主文章分类:Python ©著作权

文章标签 python 字符编码 搜索 ico firefox 文章分类 Python 后端开发

©著作权归作者所有:来自51CTO博客作者CorwinPC的原创作品,请联系作者获取转载授权,否则将追究法律责任

UnicodeEncodeError: ‘gbk’ codec can’t encode character ‘\xa9’ in position 17180: illegal multibyte sequence
这种问题一般是由于字符编码不一致造成的,很多人搜索后都会遇到这样的问题,但解决方案并不是很理想。经过摸索,我们终于得到了这样的解决方案。

[En]

This kind of problem is generally caused by inconsistent character coding, and many people encounter such problems after searching, but the solutions are not very ideal. After groping, we finally get such a solution.

import requestsimport reif __name__ == '__main__':    url = 'https://www.2meinv.com/index-1.html'    headers = {        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0'    }    response = requests.get(url=url, headers=headers).content.decode('utf-8')    r = re.sub('\xa9', '', response)    print(r)
  • 收藏
  • 评论
  • *举报

上一篇:解决SQLServer占用80端口问题

下一篇:python 字典列表指定key排序

Original: https://blog.51cto.com/YangPC/5483137
Author: CorwinPC
Title: requests请求报字符编码异常信息

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/513527/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球