How can I use python 3 to get access to the HTTP Headers. Specifically, I am trying to recreate the headers you can gain access to through network in the developer tools in chrome.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
>>> import pprint
>>> import urllib.request
>>> u = urllib.request.urlopen('http://www.python.org')
>>> pprint.pprint(dict(u.getheaders()))
{'Accept-Ranges': 'bytes',
'Connection': 'close',
'Content-Length': '18882',
'Content-Type': 'text/html',
'Date': 'Sat, 24 Dec 2011 23:51:27 GMT',
'ETag': '"105800d-49c2-4b4ab1ba443c0"',
'Last-Modified': 'Thu, 22 Dec 2011 09:41:43 GMT',
'Server': 'Apache/2.2.16 (Debian)',
'X-Pad': 'avoid browser bug'}