V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
rocketman13
V2EX  ›  问与答

爬虫:提取网页源代码转码时报错 UnicodeDecodeError

  •  
  •   rocketman13 · 2018-06-11 16:20:29 +08:00 · 579 次点击
    这是一个创建于 2171 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这是京东网页源代码写的<meta http-equiv="Content-Type" content="text/html; charset=gbk"> 但用 response.body.decode("utf-8")或者 respon.body.decode("gbk")都会报错 UnicodeDecodeError: 'gbk' codec can't decode byte 0x81 in position 88852: illegal multibyte sequence 这是什么原因呢?? 最后可以用 response.text 来解码不报错,但不明白上面使用 gbk 为什么会报错,response.text 又是将源码解码成什么格式呢??

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2495 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 15:16 · PVG 23:16 · LAX 08:16 · JFK 11:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.