import urllib
response = urllib.request.urlopen("https://www.python.org")
#返回响应的状态码
print(response.status)
#返回响应的头信息
print(response.getheaders())
#获取响应头中Server的值
print(response.getheader("Server"))
# 运行结果如下:
# 200
# [('Server', 'nginx'), ('Content-Type', 'text/html; charset=utf-8'), ('X-Frame-Options', 'SAMEORIGIN'), ('x-xss-protection', '1; mode=block'), ('X-Clacks-Overhead', 'GNU Terry Pratchett'), ('Via', '1.1 varnish'), ('Content-Length', '50114'), ('Accept-Ranges', 'bytes'), ('Date', 'Wed, 21 Nov 2018 13:57:18 GMT'), ('Via', '1.1 varnish'), ('Age', '306'), ('Connection', 'close'), ('X-Served-By', 'cache-iad2141-IAD, cache-sjc3139-SJC'), ('X-Cache', 'HIT, HIT'), ('X-Cache-Hits', '3, 17'), ('X-Timer', 'S1542808639.835715,VS0,VE0'), ('Vary', 'Cookie'), ('Strict-Transport-Security', 'max-age=63072000; includeSubDomains')]
# nginx