Grabbing headers from webpage with python

2019-09-07 16:27发布

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条回答
倾城 Initia
2楼-- · 2019-09-07 17:07
>>> 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'}
查看更多
登录 后发表回答