python urllib.parse urlparse path url路径分割

前言全局说明

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)

image


二、解析传值

#!/usr/bin/env python3
#coding: UTF-8
# -*- coding: UTF-8 -*-
import urllib.parse
print(urllib.parse.urlparse('http://www.baidu.com/aa/bb/cc/index.html?log=09'))
q=urllib.parse.urlparse('http://www.baidu.com/aa/bb/cc/index.html?log=09')[4]
print(q)

image



免责声明:本号所涉及内容仅供安全研究与教学使用,如出现其他风险,后果自负。




参考、来源:
https://www.cnblogs.com/wutou/p/18049293



posted @   悟透  阅读(17)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示