Python3 urlparse
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python3 urlparse相关的知识,希望对你有一定的参考价值。
>>> 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
以上是关于Python3 urlparse的主要内容,如果未能解决你的问题,请参考以下文章
什么是 URL 参数? (urlparse 结果中位置 #3 的元素)