@@ -49,16 +49,26 @@ or on combining URL components into a URL string.
49
49
present. For example:
50
50
51
51
>>> from urllib.parse import urlparse
52
- >>> o = urlparse(' http://www.cwi.nl:80/%7E guido/Python.html' )
52
+ >>> urlparse(" scheme://netloc/path;parameters?query#fragment" )
53
+ ParseResult(scheme='scheme', netloc='netloc', path='/path;parameters', params='',
54
+ query='query', fragment='fragment')
55
+ >>> o = urlparse(" http://docs.python.org:80/3/library/urllib.parse.html?"
56
+ ... " highlight=params#url-parsing" )
53
57
>>> o # doctest: +NORMALIZE_WHITESPACE
54
- ParseResult(scheme='http', netloc='www.cwi.nl:80', path='/%7Eguido/Python.html',
55
- params='', query='', fragment='')
58
+ ParseResult(scheme='http', netloc='docs.python.org:80',
59
+ path='/3/library/urllib.parse.html', params='',
60
+ query='highlight=params', fragment='url-parsing')
56
61
>>> o.scheme
57
62
'http'
63
+ >>> o.netloc
64
+ 'docs.python.org:80'
65
+ >>> o.hostname
66
+ 'docs.python.org'
58
67
>>> o.port
59
68
80
60
- >>> o.geturl()
61
- 'http://www.cwi.nl:80/%7Eguido/Python.html'
69
+ >>> o.geturl() # doctest: +NORMALIZE_WHITESPACE
70
+ 'http://docs.python.org:80/3/library/urllib.parse.html?highlight=params#
71
+ url-parsing'
62
72
63
73
Following the syntax specifications in :rfc: `1808 `, urlparse recognizes
64
74
a netloc only if it is properly introduced by '//'. Otherwise the
@@ -92,31 +102,30 @@ or on combining URL components into a URL string.
92
102
The return value is a :term: `named tuple `, which means that its items can
93
103
be accessed by index or as named attributes, which are:
94
104
95
- +------------------+-------+--------------------------+----------------------+
96
- | Attribute | Index | Value | Value if not present |
97
- +==================+=======+==========================+======================+
98
- | :attr: `scheme ` | 0 | URL scheme specifier | *scheme * parameter |
99
- +------------------+-------+--------------------------+----------------------+
100
- | :attr: `netloc ` | 1 | Network location part | empty string |
101
- +------------------+-------+--------------------------+----------------------+
102
- | :attr: `path ` | 2 | Hierarchical path | empty string |
103
- +------------------+-------+--------------------------+----------------------+
104
- | :attr: `params ` | 3 | Parameters for last path | empty string |
105
- | | | element | |
106
- +------------------+-------+--------------------------+----------------------+
107
- | :attr: `query ` | 4 | Query component | empty string |
108
- +------------------+-------+--------------------------+----------------------+
109
- | :attr: `fragment ` | 5 | Fragment identifier | empty string |
110
- +------------------+-------+--------------------------+----------------------+
111
- | :attr: `username ` | | User name | :const: `None ` |
112
- +------------------+-------+--------------------------+----------------------+
113
- | :attr: `password ` | | Password | :const: `None ` |
114
- +------------------+-------+--------------------------+----------------------+
115
- | :attr: `hostname ` | | Host name (lower case) | :const: `None ` |
116
- +------------------+-------+--------------------------+----------------------+
117
- | :attr: `port ` | | Port number as integer, | :const: `None ` |
118
- | | | if present | |
119
- +------------------+-------+--------------------------+----------------------+
105
+ +------------------+-------+-------------------------+------------------------+
106
+ | Attribute | Index | Value | Value if not present |
107
+ +==================+=======+=========================+========================+
108
+ | :attr: `scheme ` | 0 | URL scheme specifier | *scheme * parameter |
109
+ +------------------+-------+-------------------------+------------------------+
110
+ | :attr: `netloc ` | 1 | Network location part | empty string |
111
+ +------------------+-------+-------------------------+------------------------+
112
+ | :attr: `path ` | 2 | Hierarchical path | empty string |
113
+ +------------------+-------+-------------------------+------------------------+
114
+ | :attr: `params ` | 3 | No longer used | always an empty string |
115
+ +------------------+-------+-------------------------+------------------------+
116
+ | :attr: `query ` | 4 | Query component | empty string |
117
+ +------------------+-------+-------------------------+------------------------+
118
+ | :attr: `fragment ` | 5 | Fragment identifier | empty string |
119
+ +------------------+-------+-------------------------+------------------------+
120
+ | :attr: `username ` | | User name | :const: `None ` |
121
+ +------------------+-------+-------------------------+------------------------+
122
+ | :attr: `password ` | | Password | :const: `None ` |
123
+ +------------------+-------+-------------------------+------------------------+
124
+ | :attr: `hostname ` | | Host name (lower case) | :const: `None ` |
125
+ +------------------+-------+-------------------------+------------------------+
126
+ | :attr: `port ` | | Port number as integer, | :const: `None ` |
127
+ | | | if present | |
128
+ +------------------+-------+-------------------------+------------------------+
120
129
121
130
Reading the :attr: `port ` attribute will raise a :exc: `ValueError ` if
122
131
an invalid port is specified in the URL. See section
0 commit comments