chmod 777 j
chmod 777 j

Reputation: 567

How do you get the URL out of a http.client.HTTPResponse object?

(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

Answers (1)

alecxe
alecxe

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

Related Questions