➜ ~ ipython3 Python 3.6.5 |Anaconda custom (x86_64)| (default, Apr 26 2018, 08:42:37) Type 'copyright', 'credits' or 'license' for more information IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: from urllib.parse import urlparse In [2]: url = "https://www.168seo.cn/mac-os/24832.html" In [3]: x = urlparse(url) In [4]: x Out[4]: ParseResult(scheme='https', netloc='www.168seo.cn', path='/mac-os/24832.html', params='', query='', fragment='') In [5]: x.netloc Out[5]: 'www.168seo.cn'
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
➜
~
ipython3
Python
3.6.5
|
Anaconda
custom
(
x86_64
)
|
(
default
,
Apr
26
2018
,
08
:
42
:
37
)
Type
'copyright'
,
'credits'
or
'license'
for
more
information
IPython
6.1.0
--
An
enhanced
Interactive
Python
.
Type
'?'
for
help
.
In
[
1
]
:
from
urllib
.
parse
import
urlparse
In
[
2
]
:
url
=
"https://www.168seo.cn/mac-os/24832.html"
In
[
3
]
:
x
=
urlparse
(
url
)
In
[
4
]
:
x
Out
[
4
]
:
ParseResult
(
scheme
=
'https'
,
netloc
=
'www.168seo.cn'
,
path
=
'/mac-os/24832.html'
,
params
=
''
,
query
=
''
,
fragment
=
''
)
In
[
5
]
:
x
.
netloc
Out
[
5
]
:
'www.168seo.cn'
|
是不是挺方便的,当然你也可以截取,字符串的截取,但是比较麻烦
826

被折叠的 条评论
为什么被折叠?



