requests发送HTTP请求后返回的响应头
requests 返回的Response对象包含响应头属性 headers:
import requests as r
response = r.get("https://www.perfcode.com")
print(response.headers)
访问response.headers
属性会返回一个字典,但这个字典有点与众不同;
因为HTTP头部是大小写不敏感的,我们可以使用任意大小的形式作为键来访问这个字典:
response.headers['Content-Type']
response.headers.get('content-type')