gpt4 book ai didi

python - 如何在python中更改url查询的值?

转载 作者:行者123 更新时间:2023-12-03 16:53:47 25 4
gpt4 key购买 nike

 url = "http://www.example.com?type=a&type1=b&type2=c"
urllist = get_urllist(url)
trigger = ["'or '1'='1'"," 'OR '1'='2'","'OR a=a"]

def get_urllist(url):
url_parsed = urlparse.urlparse(url)
#extract the query parameters of the URL
query = urlparse.parse_qs(url_parsed.query)
#get the list of query
query_list = query_list(query)
#Get Base url
url = urlparse._replace(query=None).geturl()
#modify url to get url_list
for query in query_list :
# change the original query to get the expected result


return url_list


def query_list(query):
for t in trigger:
for key, value in query.items():
query[key] += t
query_list.append(query)

return query_list

如何通过更改查询参数值返回 URL 列表?

原始网址 =“ http://www.example.com?type=a&type1=b&type2=c

预期结果:

url_list= [" http://www.example.com?type=a 'OR '1'='1'&type1=b'OR '1'='1'&type2=c'OR '1'='1'"," http://www.example.com?type=a 'OR '1 '='2'&type1=b'OR '1'='2'&type2=c'OR '1'='2'"," http://www.example.com?type=a 'OR a=a&type1=b'OR a=a&type2=c' '或 a=a"]

最佳答案

在 Python2.x

您可以使用 urlparse.urlparse 功能和ParseResult._replace方法:

import urlparse
url = "http://www.example.com?type=a&type1=b&type2=c"
trigger = ["'or '1'='1'"," 'OR '1'='2'","'OR a=a"]

parsed = urlparse.urlparse(url)
querys = parsed.query.split("&")
result = []
for pairs in trigger:
new_query = "&".join([ "{}{}".format(query, pairs) for query in querys])
parsed = parsed._replace(query=new_query)
result.append(urlparse.urlunparse(parsed))

备注

urlparse 模块重命名为 urllib.parse Python 3 . 2to3 将源代码转换为 Python 3 时,该工具将自动调整导入。

在 Python3.x

您可以使用 urlparse.urlparse 功能也一样。
import urllib.parse as urlparse
url = "http://www.example.com?type=a&type1=b&type2=c"
trigger = ["'or '1'='1'"," 'OR '1'='2'","'OR a=a"]

parsed = urlparse.urlparse(url)
querys = parsed.query.split("&")
result = []
for pairs in trigger:
new_query = "&".join([ "{}{}".format(query, pairs) for query in querys])
parsed = parsed._replace(query=new_query)
result.append(urlparse.urlunparse(parsed))

演示输出:
["http://www.example.com?type=a'or '1'='1'&type1=b'or '1'='1'&type2=c'or '1'='1'", "http://www.example.com?type=a 'OR '1'='2'&type1=b 'OR '1'='2'&type2=c 'OR '1'='2'", "http://www.example.com?type=a'OR a=a&type1=b'OR a=a&type2=c'OR a=a"]

关于python - 如何在python中更改url查询的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43607870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com