顾名思义,urlsplit是拆分,而urlparse是解析,所以urlparse粒度更为细致
区别
split函数在分割的时候,path和params属性是在一起的
代码示例
# -*- coding: utf-8 -*- from urllib.parse import urlsplit, urlparse url = "https://username:password@www.baidu.com:80/index.html;parameters?name=tom#example" print(urlsplit(url)) """ SplitResult( scheme='https', netloc='username:password@www.baidu.com:80', path='/index.html;parameters', query='name=tom', fragment='example') """ print(urlparse(url)) """ ParseResult( scheme='https', netloc='username:password@www.baidu.com:80', path='/index.html', params='parameters', query='name=tom', fragment='example' ) """
参考: