How to get HTTP HEAD request with Python, and get results? Easy.
$python >>>import requests >>>r = requests.get('http://google.com') >>>r.headers {'alternate-protocol': '80:quic', 'x-xss-protection': '1; mode=block', 'transfer-e ncoding': 'chunked', 'set-cookie': 'PREF=ID=1f15ab14c12505e8: FF=0:TM=1406501237:L M=1406501237:S=hHSSoJtgc9dO1MXE; expires=Tue, 26-Jul-2016 22:47:17 GMT; path=/; do main=.google.co.il, NID=67=D8CbgklOsbelB5ei756y3rTdBBrqAxVON2vpQRxDql2tsw3rq0ANQlc ndJ8aQ37it9U6ofhaO5xx6wuQOqSX0tHp2QlNREjkwIWtFiXhy_s5L2GLXNKYjE0pkQCs9Fph; expires =Mon, 26-Jan-2015 22:47:17 GMT; path=/; domain=.google.co.il; HttpOnly', 'expires' : '-1', 'server': 'gws', 'cache-control': 'private, max-age=0', 'date': 'Sun, 27 J ul 2014 22:47:17 GMT', 'p3p': 'CP="This is not a P3P policy! See http://www.google .com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."', 'con tent-type': 'text/html; charset=windows-1255', 'x-frame-options': 'SAMEORIGIN'}
Results depends on parameters you use (follow redirects etc..)
As you can see, type of 'r.headers' is dictionary, so, you can get every value you want by key.
>>>r.headers['server'] 'gws'More info: Python Requests: HTTP for Humans
How to get HTTP HEAD with Bash?
$curl --head google.com HTTP/1.1 302 Found Cache-Control: private Content-Type: text/html; charset=UTF-8 Location: http://www.google.co.il/?gfe_rd=cr&ei=2YLVU76XNOTa8gf49YGYCw Content-Length: 261 Date: Sun, 27 Jul 2014 22:53:13 GMT Server: GFE/2.0 Alternate-Protocol: 80:quic
More info: 'man curl'
No comments:
Post a Comment