python 解析 url地址

code

macname@MacdeMacBook-Pro new % python3
Python 3.7.4 (v3.7.4:e09359112e, Jul  8 2019, 14:54:52) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> from urllib.parse import urlparse
>>> urlparse("http://192.168.0.5:5000")
ParseResult(scheme='http', netloc='192.168.0.5:5000', path='', params='', query='', fragment='')
>>> 
>>> urlparse("192.168.0.5:5000")
ParseResult(scheme='', netloc='', path='192.168.0.5:5000', params='', query='', fragment='')
>>> 
>>> urlparse("192.168.0.5:5000/p/20abb75cd983")
ParseResult(scheme='192.168.0.5', netloc='', path='5000/p/20abb75cd983', params='', query='', fragment='')
>>> 
>>> urlparse("192.168.0.5:5000/search?q=通过构建区块链来学习区块链&page=1&type=note")
ParseResult(scheme='192.168.0.5', netloc='', path='5000/search', params='', query='q=通过构建区块链来学习区块链&page=1&type=note', fragment='')
>>> 
>>> urlparse("http://192.168.0.5:5000/search?q=通过构建区块链来学习区块链&page=1&type=note")
ParseResult(scheme='http', netloc='192.168.0.5:5000', path='/search', params='', query='q=通过构建区块链来学习区块链&page=1&type=note', fragment='')
>>> 
>>> 
>>> 
>>>

原文地址:https://www.cnblogs.com/sea-stream/p/13548555.html