Archive
Posts Tagged ‘302’
Where does a page redirect to?
December 21, 2010
Leave a comment
Question
We have a page that redirects to another page. How to figure out where the redirection points to?
Answer
import urllib s = "https://pythonadventures.wordpress.com?random" # returns a random post page = urllib.urlopen(s) print page.geturl() # e.g. http:// pythonadventures.wordpress.com/2010/10/08/python-challenge-1/
Credits
I found it in this thread.
Update (20121202)
With requests:
>>> import requests
>>> r = requests.get('https://pythonadventures.wordpress.com?random')
>>> r.url
u'https://pythonadventures.wordpress.com/2010/09/30/create-import-module/'
