python gbk编码问题
https://www.cnblogs.com/GUIDAO/p/6679574.html
http://blog.csdn.net/a491057947/article/details/47292923
https://www.jianshu.com/p/b0e386361570
http://blog.csdn.net/xiaopihaierletian/article/details/72832882
测试如下:
对于
from bs4 import BeautifulSoup
import requests
news_url=’http://finance.sina.com.cn/china/20151214/004524006126.shtml’
print news_url
req = requests.get(news_url)
print req.encoding
req.encoding=requests.utils.get_encodings_from_content(req.text)[0] # req.encoding = ‘utf-8’如果是这句话,输出会有问题
#req.encoding=’gbk’
print req.headers[‘content-type’]
data = req.text
print data
soup = BeautifulSoup(data,’lxml’)
title = soup.select(‘#artibodyTitle’)[0].text
print(title)
转载自:https://blog.csdn.net/tianshuijun12/article/details/78919502