gpt4 book ai didi

python - 如何在 Python 中使用 referer 和 href 查找 url?

转载 作者:太空宇宙 更新时间:2023-11-04 08:23:10 24 4
gpt4 key购买 nike

假设我有

window_location = 'http://stackoverflow.com/questions/ask'
href = '/users/48465/jader-dias'

我要获取

link = 'http://stackoverflow.com/users/48465/jader-dias'

我如何在 Python 中执行此操作?

它必须像在浏览器中一样工作

最佳答案

>>> import urlparse
>>> urlparse.urljoin('http://stackoverflow.com/questions/ask',
... '/users/48465/jader-dias')
'http://stackoverflow.com/users/48465/jader-dias'

来自 urlparse.urljoin 的文档页面:

urlparse.urljoin(base, url[, allow_fragments])

Construct a full (“absolute”) URL by combining a “base URL” (base) with another URL (url). Informally, this uses components of the base URL, in particular the addressing scheme, the network location and (part of) the path, to provide missing components in the relative URL.

If url is an absolute URL (that is, starting with // or scheme://), the url‘s host name and/or scheme will be present in the result.

关于python - 如何在 Python 中使用 referer 和 href 查找 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1250371/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com