我想为例如- www.xyz.com
它是一个身份验证 url,点击后会在 url 栏上生成新的 url,例如www.xyz-11.com
如何从 python 中检索它?
调用 url 并获取新创建的 url?
请您参考如下方法:
>>> 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/'
另见 the documentation for urllib2.urlopen ;
geturl()— return the URL of the resource retrieved, commonly used to determine if a redirect was followed
