【发布时间】:2012-06-05 07:34:50
【问题描述】:
我正在尝试从不同的部分形成 URL,但无法理解此方法的行为。例如:
Python 3.x
from urllib.parse import urljoin
>>> urljoin('some', 'thing')
'thing'
>>> urljoin('http://some', 'thing')
'http://some/thing'
>>> urljoin('http://some/more', 'thing')
'http://some/thing'
>>> urljoin('http://some/more/', 'thing') # just a tad / after 'more'
'http://some/more/thing'
urljoin('http://some/more/', '/thing')
'http://some/thing'
你能解释一下这个方法的确切行为吗?
【问题讨论】:
-
遇到这个问题的人请注意:上面的 import 语句适用于 Python 3.x。对 python 2.x 使用“from urlparse import urljoin”。
标签: python python-3.x