import base64 import hashlib import requests import json from logzero import logger http_app_secret = 'XXXXXXXXXXXX' http_app_id = 'XXXXXXXX' def str_encrypt(str): """ 使用sha1加密算法,返回str加密后的字符串 """ sha = hashlib.sha1(str) encrypts = sha.hexdigest() return encrypts params = { 'houseCode': '101111010102', 'cityId': '110000', 'fb_expo_id': '462726273153150977', } def get_authorization(params): p_list = [] for key, val in params.items(): s_line = '%s=%s' % (key, val) p_list.append(s_line) p_list.sort() sb = http_app_secret + "".join(p_list) logger.info(sb) instance = str_encrypt(sb.encode()) logger.info(instance) bs = http_app_id + ":" + instance logger.info(bs) encoder = base64.b64encode(bs.encode("utf-8")) logger.info(encoder) return encoder url = 'https://app.api.ke.com/house/ershoufang/detailpart1v2' headers = { 'Host': 'app.api.ke.com', 'Authorization': get_authorization(params), # 'x-req-id': 'c33e78e2-94d8-4c87-b09e-6cd22f3973c1', 'Page-Schema': 'ershou%2Fdetail', 'Referer': 'community%2Fershoulist', 'Cookie': 'lianjia_udid=fd6275273712c97c;lianjia_ssid=db0ad3c2-da83-4806-a726-b87c3a7be016;algo_session_id=0c935a9e-5ad2-40c3-b383-08ceff3e929c;lianjia_uuid=4f514342-8349-4596-a4df-ad6540d45db8', 'Dynamic-SDK-VERSION': '1.1.0', 'Lianjia-City-Id': '110000', # 'parentSceneId': '5640895386532073216', 'source-global': '{}', 'User-Agent': 'Beike2.58.0;google Pixel+3; Android 9', # 'Lianjia-Channel': 'Android_ke_tencentd', # 'Lianjia-Device-Id': 'fd6275273712c97c', 'Lianjia-Version': '2.58.0', # 'Lianjia-Im-Version': '2.34.0', # 'Lianjia-Recommend-Allowable': '1', # 'Authorization':'MjAxODAxMTFfYW5kcm9pZDo5ODkxZjQxYTA2YjVmZWRmMjU4NzI5NTMxZDUzNDZiZDkxM2NjZDEz', # 'extension': 'lj_duid=null&ketoken=TxocRRR8gdDCVkmPzjVOxyC1kVuGFdhcKiYL7BO9nXwObhtCPKKsYdYziLCFcFDw0XluhtsgqwRrzuB5clwZTWE5REOJERbG1rQQJ8aA8AiZK1wHLb3SIBzz6OAz2zIw&lj_android_id=fd6275273712c97c&lj_device_id_android=fd6275273712c97c&mac_id=F0:5C:77:E7:91:6B', # 'ip': '182.140.153.28', # 'wifi_name': 'Tencent-WiFi', # 'lat': '30.552499', # 'lng': '104.068037', # 'beikeBaseData': '%7B%22duid%22%3A%22%22%7D', # 'WLL-KGSA':'LJAPPVA accessKeyId=sjoe98HI099dhdD7; nonce=PiLT6U8QIR8JAZtPbmtRDHbiUF1BEmzc; timestamp=1625123574; signature=q3pLpmpHmDiWCcOArtYFrWULD2ues5EB2bTOHhEl6/U=', # 'Host':'app.api.ke.com', # 'Connection':'Keep-Alive', # 'Accept-Encoding':'gzip', # 'If-Modified-Since': 'Wed, 30 Jun 2021 13:17:18 GMT' } r = requests.get(url, params=params, headers=headers) logger.info(r.text)