爬虫requests爬去网页乱码问题

1:res.apparent_encoding

2:res.encoding='utf-8'

r.encoding从HTTP header中猜测的响应内容编码方式
r.apparent_encoding从内容中分析出的响应内容编码方式(备选编码方式)

                r.encoding:如果header中不存在charset,则认为编码为ISO-8859-1
                r.apparent_encoding:根据网页内容分析出的编码方式

res.encoding=res.apparent_encoding

 

                                  https://www.jianshu.com/p/d78982126318

 

import requests
url = 'http://www.chinanews.com/gn/2018/05-24/8521399.shtml'
res = requests.get(url)
res.content
res.encoding #获取res的编码格式
res.headers #获取Content-Type内容
res.apparent_encoding #获取网页正确的编码格式
#html = res.text# 返回的结果是处理过的Unicode类型的数据
print(res.encoding)#获得网页源码的格式 打印显示 ISO-8859-1
print(res.content){网上一个大神的实验}

posted on 2018-05-24 22:22 leolaosao 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/leolaosao/p/9085462.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值