直接结论:别依赖response.apparent_encoding,优先用response.content+chardet.detect()或手动检查meta标签定编码,再显式设response.encoding;不确定时用decode()自行处理字节流更可控。

直接结论:别依赖 response.apparent_encoding,优先用 response.content + chardet.detect() 或手动检查 meta 标签来定编码,再显式设 response.encoding;不确定时,用 decode() 自行处理字节流更可控。
为什么 response.apparent_encoding 经常不准
requests 的这个属性本质是调用 chardet 做启发式统计,对短页面、纯 ASCII 内容、无 BOM 的 GBK 页面极易误判。比如一个只含 <meta charset="gbk"> 鐨勫搷搴旓紝apparent_encoding 鍙


















