Created
December 9, 2014 10:46
-
-
Save haseebr/53dfdac3445cfb2af755 to your computer and use it in GitHub Desktop.
Answer to a Quora Question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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