Skip to content

Instantly share code, notes, and snippets.

@pronto
Created September 3, 2014 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pronto/01ad52032ebd8ad20488 to your computer and use it in GitHub Desktop.
Save pronto/01ad52032ebd8ad20488 to your computer and use it in GitHub Desktop.
http server head location follow
it follows the header location FOR EVER
% ./head.py http://t.co/xoE6KECoaL
http://ift.tt/Wcf2oC
https://plus.google.com/109306878344142850405/posts/a9MCxCwvN4x
https://plus.google.com/+FredRichards/posts/a9MCxCwvN4x
#!/usr/bin/env python2.7
import requests
import sys
def get_loc(url):
try:
h=requests.head(url).headers['location']
return h
except KeyError:
return 'END'
urlcnt=len(sys.argv)-1
if urlcnt == 0:
print 'please enter in a url'
sys.exit(1)
headloop = get_loc(sys.argv[1])
while headloop != 'END':
print headloop
headloop = get_loc(headloop)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment