标签:cas query pat host name nal param html word pytho
>>> from urllib.parse import urlparse >>> o = urlparse(‘http://www.cwi.nl:80/%7Eguido/Python.html‘) >>> o ParseResult(scheme=‘http‘, netloc=‘www.cwi.nl:80‘, path=‘/%7Eguido/Python.html‘, params=‘‘, query=‘‘, fragment=‘‘) >>> o.scheme ‘http‘ >>> o.port 80 >>> o.geturl() ‘http://www.cwi.nl:80/%7Eguido/Python.html‘
>>> from urllib.parse import urlparse >>> urlparse(‘//www.cwi.nl:80/%7Eguido/Python.html‘) ParseResult(scheme=‘‘, netloc=‘www.cwi.nl:80‘, path=‘/%7Eguido/Python.html‘, params=‘‘, query=‘‘, fragment=‘‘) >>> urlparse(‘www.cwi.nl/%7Eguido/Python.html‘) ParseResult(scheme=‘‘, netloc=‘‘, path=‘www.cwi.nl/%7Eguido/Python.html‘, params=‘‘, query=‘‘, fragment=‘‘) >>> urlparse(‘help/Python.html‘) ParseResult(scheme=‘‘, netloc=‘‘, path=‘help/Python.html‘, params=‘‘, query=‘‘, fragment=‘‘)
Attribute | Index | Value | Value if not present |
---|---|---|---|
scheme |
0 | URL scheme specifier | scheme parameter |
netloc |
1 | Network location part | empty string |
path |
2 | Hierarchical path | empty string |
params |
3 | Parameters for last path element | empty string |
query |
4 | Query component | empty string |
fragment |
5 | Fragment identifier | empty string |
username |
User name | None |
|
password |
Password | None |
|
hostname |
Host name (lower case) | None |
|
port |
Port number as integer, if present | None |
来源:https://docs.python.org/3/library/urllib.parse.html?highlight=urlparse#urllib.parse.urlparse
标签:cas query pat host name nal param html word pytho
原文地址:http://www.cnblogs.com/itlqs/p/6055365.html