Python编程:urlsplit, urlparse简单区别

版权声明:本文为博主原创文章,欢迎转载,请注明出处 https://blog.csdn.net/mouday/article/details/85613666

顾名思义,urlsplit是拆分,而urlparse是解析,所以urlparse粒度更为细致

区别
split函数在分割的时候,path和params属性是在一起的

代码示例

# -*- coding: utf-8 -*-

from urllib.parse import urlsplit, urlparse

url = "https://username:[email protected]:80/index.html;parameters?name=tom#example"

print(urlsplit(url))
"""
SplitResult(
    scheme='https', 
    netloc='username:[email protected]:80', 
    path='/index.html;parameters', 
    query='name=tom', 
    fragment='example')
"""

print(urlparse(url))
"""
ParseResult(
    scheme='https', 
    netloc='username:[email protected]:80', 
    path='/index.html', 
    params='parameters', 
    query='name=tom', 
    fragment='example'
)
"""

参考:
Python教程:[20]urlsplit和urlparse的区别

猜你喜欢

转载自blog.csdn.net/mouday/article/details/85613666