假设我有
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.
我是一名优秀的程序员,十分优秀!