Reputation: 567
(Using python3.4)
Lets say you ran some code like this:
from urllib import request
some_url = request.urlopen('http://en.wikipedia.org/wiki/Special:Random')
After accessing the url .../wiki/Special:Random the url will promptly change to something like .../wiki/Python_(programming_language). How would you get the new url out of some_url?
Upvotes: 1
Views: 1017
Reputation: 474141
Use the .url
:
>>> from urllib import request
>>> r = request.urlopen('http://en.wikipedia.org/wiki/Special:Random')
>>> r.url
'http://en.wikipedia.org/wiki/Shades_Mountain'
or .geturl()
:
>>> r.geturl()
'http://en.wikipedia.org/wiki/Shades_Mountain'
Upvotes: 3