python - 打开 url 并检索更改的 url

发布于 2024-11-16 01:43:48 字数 137 浏览 1 评论 0原文

我想调用一个网址,例如 - www.xyz.com,

点击后会在网址栏上生成新的网址,例如 www.xyz-11.com,它是一个身份验证网址,

如何从 python 检索此网址?
调用 url 并获取新创建的 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

开始看清了 2024-11-23 01:43:48
>>> 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/'

另请参阅 urllib2.urlopen 的文档;

  • geturl() — 返回检索到的资源的 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/'

See also the documentation for urllib2.urlopen;

  • geturl() — return the URL of the resource retrieved, commonly used to determine if a redirect was followed
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文