编程题:给一个网址获取分配网址的协议,域名,路径,端口,参数1的值,参数2的值,并以字典的形式打印出结果【杭州多测师】【杭州多测师_王sir】

时间:2022-10-26 12:02:33
代码如下:

def func():
url = 'http://duoceshi.cn:7076/share/index.html?shareVideoId=-721509&playType=1'
dict1={}
parms = [i for i in url.split('?')]
dict1['协议'] = parms[0].split(':')[0]
dict1['多测师域名'] = parms[0].split('//')[1].split(':')[0]
dict1['端口'] = parms[0].split(':')[2].split('/')[0]
dict1['路径'] = parms[0].split('7076')[1]
for j in parms[1].split('&'):
a = j.split('=')
dict1[a[0]]=a[1]
print(dict1)
func()

输出结果如下:
{'协议': 'http', '多测师域名': 'duoceshi.cn', '端口': '7076', '路径': '/share/index.html',
'shareVideoId': '-721509', 'playType': '1'}