1. 程式人生 > >Python程式設計:urlsplit, urlparse簡單區別

Python程式設計:urlsplit, urlparse簡單區別

顧名思義,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的區別