再也不用担心网页编码的坑了!
背景
大家爬取网页的时候,应该都遇到过这种情况
当我打印网页源代码的时候
发现 全部是乱码的
那这个时候应该怎么办呢?
requests是如何判断编码
首先,response.content返回的内容 是二进制内容
response.text 则是根据设置的encoding来解码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Try charset from content-type
content = None
encoding = self.encoding
if not self.content:
return