Python 拆分 URL

>>> from urllib.parse import urlparse
>>> url = urlparse("https://baidu.com/a/b?code=1&search=1&page=2")
>>> url
ParseResult(scheme='https', netloc='baidu.com', path='/a/b', params='', query='code=1&search=1&page=2', fragment='')

>>> url.scheme
'https'
>>> url.port

>>> url.geturl()
'https://baidu.com/a/b?code=1&search=1&page=2'

>>> url.scheme
'https'

>>> url.netloc
'baidu.com'

>>> url.path
'/a/b'

>>> url.query
'code=1&search=1&page=2'

Last updated