requests.get.headers


The for loop returns the headers values.
 >>> import requests
>>> r=requests.get('http://www.pythonlake.com/aboutus')
>>> for s in r.headers:
...     print(s)
... 
x-xss-protection
transfer-encoding
x-content-type-options
vary
expires
content-type
server
date
cache-control
accept-ranges
last-modified
x-robots-tag
alternate-protocol


The headers returns with the server response to get request and if statement is used to open the webbrowser condition to dict.keys.

 >>>import requests
>>> re=requests.get('http://www.pythonlake.com', params='Pythonlake')
>>> re.headers
{'x-content-type-options': 'nosniff', 'server': 'GSE', 'x-robots-tag': 'noarchive', 'x-xss-protection': '1; mode=block', 'date': 'Mon, 27 Apr 2015 13:27:21 GMT', 'accept-ranges': 'none', 'vary': 'Accept-Encoding', 'cache-control': 'public, max-age=5', 'transfer-encoding': 'chunked', 'content-type': 'text/html; charset=utf-8', 'last-modified': 'Mon, 27 Apr 2015 13:16:45 GMT', 'expires': 'Mon, 27 Apr 2015 13:27:26 GMT', 'alternate-protocol': '80:quic,p=1,80:quic,p=1'}
>>> 
>>> h.keys
<bound method CaseInsensitiveDict.keys of {'x-content-type-options': 'nosniff', 'server': 'GSE', 'x-robots-tag': 'noarchive', 'x-xss-protection': '1; mode=block', 'date': 'Mon, 27 Apr 2015 13:27:21 GMT', 'accept-ranges': 'none', 'vary': 'Accept-Encoding', 'cache-control': 'public, max-age=5', 'transfer-encoding': 'chunked', 'content-type': 'text/html; charset=utf-8', 'last-modified': 'Mon, 27 Apr 2015 13:16:45 GMT', 'expires': 'Mon, 27 Apr 2015 13:27:26 GMT', 'alternate-protocol': '80:quic,p=1,80:quic,p=1'}>
>>> if 'server' in h.keys():
...     >>> webbrowser.open_new('www.pythonlake.com')
True
>>>


Comments