2 回答
TA贡献1780条经验 获得超1个赞
尝试使用临时变量在循环中构建 url,然后在最后打印,如下所示:
result = f'{base_url}?'
for i in myparms1:
result = result + f'{i}=myparms1[i]&'
# remove extra & at end after last parameter
result = result[:-1]
print(result)
TA贡献1810条经验 获得超4个赞
#!/usr/bin/env python3
def findingParams(url):
if "?" not in url:
print(url)
else:
base_url, parameters = url.split("?")
payload = "modified_value"
if "&" in parameters:
modif = ""
for params in parameters.split("&"):
name, value = params.split("=")
modif += name + "=" + payload + "&"
print(base_url + "?" + modif.strip("&"))
else:
print(url.split("=")[0] + "=" + payload)
findingParams("testme.com/test.php")
# testme.com/test.php
findingParams("testme.com/test.php?name=123")
# testme.com/test.php?name=modified_value
findingParams("testme.com/test.php?name=12345&test=12345")
# testme.com/test.php?name=modified_value&test=modified_value
findingParams("testme.com/test.php?name=12345&test=12345&foo=12345")
# testme.com/test.php?name=modified_value&test=modified_value&foo=modified_value
添加回答
举报