import requests
url = 'https://www.zhihu.com/people/kaifulee/activities'
headers = {
'authorization': 'oauth c3cef7c66a1843f8b3a9e6a1e3160e20',
'accept': 'application/json, text/plain, */*',
'accept-encoding': 'deflate, br',
'accept-language': 'zh-CN,zh;q=0.9',
'referer': 'https://www.zhihu.com/people/tan-shi-san-57/following',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
'x-udid': 'AIBCI1Wl0gyPTn67_E1wN4NxZ3rOI2offMM=',
}
r = requests.get(url, headers=headers)
print(r.headers['content-type'], r.encoding)
print(r.text)
打印部分输出:
text/html; charset=utf-8 utf-8
ȣ?�Z��=�j�t yrb.@�m�5&H疦�6���Mj��y��������IР�����3���ĢtA5S�!���W���f�ր�ef�R����BX5��p:���s�p��5A-�K�!$�xr�
�� ~�2t���%C�ӝ���p7|��GA��6w����);�pՍ��~��8�֭�;8�ᒽ8�Ya�������z������L�qX�KN�����$Ad�Q0H�f�RY-�� V��huZ&JP�<�5�5+��������$R� ��)T�>�2TAi��C�ö{y��,�v)�M�.�7q���9�3Aͅ�����@��5��b>����5G�%sR��2o���@����o��4P��`��s���LjmL���1=?���5�9�(�� }���s/ Qe�ml�����Ɣ}�s�����Tr"�>?�
'accept-encoding': 'deflate, br',
你把这个去掉,就返回正常了;你现在这个是返回的是压缩了的,除非你读取响应头,看看服务端到底使用何种压缩算法,进行解压。