企查查列表页参数处理

287 阅读2分钟

1 企查查列表页加密参数处理

# !usr/bin/env python
# -*-coding:utf-8-*-
"""
@Author:Perpetually 
@email:perpetually2014@icloud.com
@Blog:https://github.com/perpetually
 
@File:get_key.py
@Time:2023.8.28 9:55
"""

# by Ganxiaozhe (hi@gxzv.com)
# 2022-11-29
# https://gxzv.com/blog/qcc_headers_hash/
#
import json
import hashlib
import hmac
import re

import requests

# 在这里填写请求数据

req_url = '/api/elib/getTecList'

req_data = {
    'pageSize': 20,
    'areaFilters': [],
    'honorType': [
        '1_1',
    ],
    'compTypes': [],
    'flag': [],
    'rangeFilters': [],
    'statusCode': '',
    'industry': [],
    'searchKey': '',
    'pageIndex': 2,
}


win_tid = '3f2985212728a18751d25bbf178cdb2d'


def get_tid():
    cookies = {
        'qcc_did': '9b2ff37c-61f9-409e-be9f-db87029b2f6e',
        'UM_distinctid': '18a2cb1f4b410c3-09e6827bc8ec6e-7f5d547e-1fa400-18a2cb1f4b51150',
        'CNZZDATA1254842228': '1749023643-1692966975-https%253A%252F%252Fwww.qcc.com%252F%7C1692966976',
        'QCCSESSID': 'eb67b4d824a8d962b4323f9bf0',
        'acw_tc': '7ae40f0c16932026605371854eca036eeee91dce1ac6e9471440b2fec7',
    }

    headers = {
        'authority': 'www.qcc.com',
        'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
        'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
        'cache-control': 'max-age=0',
        'sec-ch-ua': '"Chromium";v="116", "Not)A;Brand";v="24", "Microsoft Edge";v="116"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
        'sec-fetch-dest': 'document',
        'sec-fetch-mode': 'navigate',
        'sec-fetch-site': 'same-origin',
        'sec-fetch-user': '?1',
        'upgrade-insecure-requests': '1',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Edg/116.0.1938.54',
    }

    params = {
        'tec': 'T_TSMES',
    }

    response = requests.get('https://www.qcc.com/web/elib/teclist', params=params, cookies=cookies, headers=headers)
    html = response.text

    tid = re.findall("window.tid='(.*?)'</script>", html)
    tid = ''.join(tid)

    return tid


def seeds_generator(s):
    seeds = {
        "0": "W",
        "1": "l",
        "2": "k",
        "3": "B",
        "4": "Q",
        "5": "g",
        "6": "f",
        "7": "i",
        "8": "i",
        "9": "r",
        "10": "v",
        "11": "6",
        "12": "A",
        "13": "K",
        "14": "N",
        "15": "k",
        "16": "4",
        "17": "L",
        "18": "1",
        "19": "8"
    }
    seeds_n = 20

    if not s:
        s = "/"
    s = s.lower()
    s = s + s

    res = ''
    for i in s:
        res += seeds[str(ord(i) % seeds_n)]
    return res


def a_default(url: str = '/', data: object = {}):
    url = url.lower()
    dataJson = json.dumps(data, ensure_ascii=False, separators=(',', ':')).lower()

    hash = hmac.new(
        bytes(seeds_generator(url), encoding='utf-8'),
        bytes(url + dataJson, encoding='utf-8'),
        hashlib.sha512
    ).hexdigest()
    return hash.lower()[8:28]


def r_default(url: str = '/', data: object = {}, tid: str = ''):
    url = url.lower()
    dataJson = json.dumps(data, ensure_ascii=False, separators=(',', ':')).lower()

    payload = url + 'pathString' + dataJson + tid
    key = seeds_generator(url)

    hash = hmac.new(
        bytes(key, encoding='utf-8'),
        bytes(payload, encoding='utf-8'),
        hashlib.sha512
    ).hexdigest()
    return hash.lower()
    

data_key = {'totlacount': 633, 'page': 33, 'data_key': '13_2', 'data_type': '隐形冠军企业(省级)'}
page = 1
json_data = {
    'pageSize': 20,
    'areaFilters': [],
    'honorType': [
        data_key,
    ],
    'compTypes': [],
    'flag': [],
    'rangeFilters': [],
    'statusCode': '',
    'industry': [],
    'searchKey': '',
    'pageIndex': page,
}
key = a_default(req_url, json_data)
value = r_default(req_url, json_data, win_tid)
print(key)
print(value)

通过获取key和value对列表页headers进行请求