Skip to content

Instantly share code, notes, and snippets.

@haseebr
Created December 9, 2014 10:46
Show Gist options
  • Save haseebr/53dfdac3445cfb2af755 to your computer and use it in GitHub Desktop.
Save haseebr/53dfdac3445cfb2af755 to your computer and use it in GitHub Desktop.
Answer to a Quora Question
import requests
requests.packages.urllib3.disable_warnings() # To disable ugly warnings
url = 'http://bit.ly/1vIaXHA'
def show_redirects(url): # Recursive Function
r = requests.get(url, verify = False, allow_redirects = False)
if r.status_code == 301: # If url redirects, print the destination url and follow it.
print 'redirecting to ', r.headers['location'], '...'
show_redirects(r.headers['location'])
show_redirects(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment