Python程式設計:urlsplit, urlparse簡單區別
阿新 • • 發佈:2019-01-03
顧名思義,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'
)
"""