只需要提供参数就能够正确返回加密参数, 如下所示:
import time
import httpx
from rich import print, json
# 请求远程数据
def get_remote_data(api_name, uid=None, sid=None, headers=None):
base_url = 'http://xxx.xxx.xxx.xxx:9997/api/' # 可以联系我获取远程服务器的ip地址
default_headers = {'uid': uid, 'sid': sid}
if headers:
updated_headers = {}
for k, v in headers.items():
if isinstance(v, dict):
updated_headers[k] = json.dumps(v)
else:
updated_headers[k] = str(v)
default_headers.update(updated_headers)
try:
with httpx.Client(http2=False) as client:
data = client.post(base_url + api_name, headers=default_headers)
if data.status_code != 200:
return None, data.status_code
data = data.json()
headers_dict = json.loads(data.get('headers', '{}'))
url = data.get('url')
post_data = {'data': data.get('data')}
if 'wua' in data:
post_data['wua'] = data.get('wua')
headers_dict['Cookie'] = ''
response = client.post(url,
data=post_data,
headers=headers_dict)
if response.status_code != 200:
return response.json(), response.status_code
return response.json(), response.json().get('ret')[0]
except httpx.RequestError as e:
return None, f"请求出错: {e}"
if __name__ == '__main__':
map = {
'apiName': 'mtop.relationrecommend.mtoprecommend.recommend',
'apiVersion': '1.0',
'isEnableWua': '0',
'app': 'taoBao',
'json': {
'NewSearch_isNewSearchJump': 'false',
'appId': 'xx',
'active_bd': '1',
'addToHistory': 'true',
'apptimestamp': str(int(time.time())),
'canP4pVideoPlay': 'true',
'client_os_version': '30',
'display_text': 'mac',
'elderHome': 'false',
'from': 'hintq_home',
'globalLbs': '{}',
'goodPriceVersion': 'true',
'gpsEnabled': 'false',
'grayHair': 'false',
'hasPreposeFilter': 'false',
'info': 'wifi',
'isBeta': 'false',
'isEnterSrpSearch': 'true',
'is_multi_hintq': 'false',
'n': '10',
'needTabs': 'true',
'network': 'wifi',
'newSortBar': 'true',
'nsNative': 'true',
'page': '1',
'q': 'mac book pro', # 这里更换搜索内容
'rainbow': '2237,4614,12628338',
'scm': '2041.home_topbar.searchbutton.d',
'searchElderHomeOpen': 'false',
'spm': 'a2932.13.searchbar.searchbutton',
'style': 'list',
'sversion': '20.8',
}
}
data, msg = get_remote_data('customJson', 'uid', 'sid', map)
print(data, msg)
有需要的可以私信我学习交流
说明: 此代码仅供用于学习交流, 切勿用于非法用途