开发者社区> 问答> 正文

python urlopen 乱码?报错

urllib.request.Request("http://www.taojishu.net/?11111").read().decode('gbk')

打开此网站decode就报错,具体是什么原因呢

展开
收起
爱吃鱼的程序员 2020-06-10 11:00:21 506 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    页面里可能有其他编码,你可以用.decode('gdk',errors='ignore')或者.decode('gdk',errors='replace')来解码

    urllib.request.urlopen('http://www.taojishu.net/?11111').read().decode('gbk')

    不过不知道为什么这样会出现403错误,用requests没问题,建议用requests:

    r=requests.get('http://www.taojishu.net/?11111')

    print(r.text)

    2020-06-10 11:00:37
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载