Python两次不同的请求同一url后的响应比较获取不同处(diff、差异值)

2024-01-10 01:23:08

需求

1. 请求参数不同

2. 分别请求同一个url

3. 比较两次请求后的响应

4. 获取差异值

代码

diff.py

def diff_text(text1, text2):
    diff = ""
    for line in text1.split("\n"):
        if not line in text2:
            diff += line + "\n"
    return diff


def requester(method, param):
    if method == "POST":
        r = requests.post()
    elif method == "GET":
        r = requests.get()
    return r


r1 = requester("post", "")
r2 = requester("post", "payload")
diff = diff_text(r1.text, r2.text)
print(diff)

文章来源:https://blog.csdn.net/u012206617/article/details/135410549
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。