python urlparse 计算相对url对应的完整url

python的urlparse提供url处理相关的方法,包括url拆分,url拼接等等。html

假定baseUrl为 http://www.xxx.com/xx/abc.htmlpython

相对url为def.htmlurl

能够经过下面代码计算相对url对应的完整url:code

from urlparse import urljoin

print urljoin('http://www.xxx.com/xx/abc.html','def.html')
print urljoin('http://www.xxx.com/xx/abc.html','/index.html')

将输出:

http://www.xxx.com/xx/def.htmlhtm

http://www.xxx.com/index.htmlclass

相关文章
相关标签/搜索