import requests


def fetch_json_package(url, host, referer, encoding):
    """
    JSON抓包函数

    :param url: AJAX API地址
    :param host: 目标服务器
    :param referer: header的引用页
    :param encoding: 编码
    :return: 字典格式的JSON数据包
    """

    kv = {'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
                        'Chrome/80.0.3987.132 Safari/537.36',
          'host': host,
          'referer': referer
          }
    r = requests.get(url, headers=kv)
    r.raise_for_status()
    r.encoding = encoding
    return r.text