前言全域性說明
python urllib.parse urlparse path url路徑分割
一、獲取路徑部分
#!/usr/bin/env python3
#coding: UTF-8
# -*- coding: UTF-8 -*-
from urllib.parse import urlparse
url = 'http://www.baidu.com/aa/bb/cc/index.html'
print("url:", url)
parsed_result = urlparse(url)
print("Path:", parsed_result.path)
path_split = parsed_result.path.split('/')
print("path_split:", path_split)
path_split_1 = parsed_result.path.split('/')[:-1]
print("path_split_1:", path_split_1)
path_join = '/'.join(path_split_1)
print("path_join:", path_join)
免責宣告:本號所涉及內容僅供安全研究與教學使用,如出現其他風險,後果自負。
參考、來源:
https://www.cnblogs.com/wutou/p/18049293