Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirection url using urllib in Python 3

I would need to know what is my final URL when following redirections using urllib in Python 3.

Let's say I've some code like :

opener = urllib.request.build_opener()
request = urllib.request.Request(url)
u = opener.open(request)

If my urls redirects to another website, how can I know this new website URL ? I've found nothing useful in documentation.

Thanks for your help !

like image 791
Guillaume Lebourgeois Avatar asked Feb 09 '11 14:02

Guillaume Lebourgeois


1 Answers

You can simply use

u.geturl()

to get the URL you were redirected to (or the original one if no redirect happened).

like image 92
Sven Marnach Avatar answered Oct 12 '22 19:10

Sven Marnach