sam
sam

Reputation: 19164

python - open url and retrieve changed url

I want to call a url for e.g. - www.xyz.com

its a authentication url after clicking on which produce new url on url bar e.g. www.xyz-11.com

how can retrieve this from python?
to call a url and to get the newly created url?

Upvotes: 1

Views: 832

Answers (1)

Chris Morgan
Chris Morgan

Reputation: 90762

>>> import urllib2
>>> u = urllib2.urlopen('http://google.com')
>>> dir(u)  # useful in seeing what's there, see also help(u)
['__doc__', '__init__', '__iter__', '__module__', '__repr__', 'close', 'code', 'fileno', 'fp', 'getcode', 'geturl', 'headers', 'info', 'msg', 'next', 'read', 'readline', 'readlines', 'url']
>>> u.geturl()
'http://www.google.com.au/'
>>> u.url
'http://www.google.com.au/'

See also the documentation for urllib2.urlopen;

  • geturl() — return the URL of the resource retrieved, commonly used to determine if a redirect was followed

Upvotes: 6

Related Questions