import sys
import urllib
from urllib.parse import urlparse

import requests
from loguru import logger


def main():
    report_link = "https://www.baidu.com/tools?url=https%3A%2F%2Fwww.yunzhiju.net%2Fzxysx%2F11456.html&jump=http%3A%2F%2Fjubao.baidu.com%2Fjubao%2Faccu%2F%3Ftitle%3D%2501%25E5%25A6%2582%25E4%25BD%2595%2501%25E9%2580%259A%25E8%25BF%2587%2501%25E7%259B%25B4%25E6%2592%25AD%2501%25E6%2590%25AC%25E5%25AE%25B6%2501app%2501%25E4%25B8%258B%25E8%25BD%25BD%2501%25E5%25AE%2598%25E6%2596%25B9%2501%25E6%25AD%25A3%25E7%2589%2588%2501%25E5%25AE%2589%25E8%25A3%2585%2501%25E5%25B9%25B6%2501%25E4%25BD%2593%25E9%25AA%258C%2501%25E4%25BE%25BF%25E6%258D%25B7%2501%25E7%259A%2584%2501%25E6%2590%25AC%25E5%25AE%25B6%2501%25E6%259C%258D%25E5%258A%25A1%2501%253F%2501-%2501%25E4%25BA%2591%2501%25E4%25B9%258B%2501...%26q%3Dwww.yunzhiju.net%252Fzxysx%252F11456.html%26has_gw%3D0%26has_v%3D0&key=surl"
    proxy_link = "http://localhost:7890"
    proxies = {
        "http": proxy_link,
        "https": proxy_link,
    }
    response = requests.get(report_link, proxies=proxies, timeout=5, allow_redirects=False)
    location = response.headers["Location"]
    if not location:
        logger.warning("没有获取到举报链接的 Location")
        return

    parsed_url = urllib.parse.urlparse(response.headers["Location"])
    query_params = urllib.parse.parse_qs(parsed_url.query)
    decoded_params = {
        key: [urllib.parse.unquote(value) for value in values] for key, values in query_params.items()
    }

    print(decoded_params)


if __name__ == '__main__':
    main()
