使用requests模块爬取某中文小说网站,获取到的内容为乱码
import requests
url = "http://www.biquge.info/1_1245/21028344.html"
resp = requests.get(url)
print(resp.text)
查看网页编码为UTF-8, 添加两行代码,恢复正常
import requests
url = "http://www.biquge.info/1_1245/21028344.html"
resp = requests.get(url)
resp.encoding = 'GBK'
resp.encoding = 'utf-8'
print(resp.text)