废话不多说,直接上源码,需要技术支持的私。
一、调用js方法:
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Author: byc6352
File: jdh5st.py
Time: 2024/10/25 08:03
Technical Support:byc6352 or metabycf or 39848872 or t:byc01
-------------------------------------------------
Change : 2024/10/25 08:03
-------------------------------------------------
Desc:
"""
import json
import random
import re
import subprocess
import time
from functools import partial
from curl_cffi import requests
from loguru import logger
subprocess.Popen = partial(subprocess.Popen, encoding="utf-8")
import execjs
import function
cookie=None
js = execjs.compile(open("./jd_h5st_encrypt.js", "r", encoding="utf-8").read())
def load_cookie():
global cookie
try:
text=function.loadfromfile("cookie.txt")
cookie=function.cookies_raw_to_dic(text)
##print(cookie)
except Exception as e:
print('do_GET:error:', e)
print(e.__traceback__.tb_frame.f_globals["__file__"]) # 发生异常所在的文件
print(e.__traceback__.tb_lineno) # 发生异常所在的行数
def gen_pvid():
e = int(time.time() * 1000)
uuid_template = "xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx"
uuid = list(uuid_template)
for i, char in enumerate(uuid):
if char in ['x', 'y']:
n = int((e + 16 * random.random()) % 16)
e = e // 16
if char == 'x':
uuid[i] = hex(n)[2:]
elif char == 'y':
uuid[i] = hex((3 & n | 8) % 16)[2:]
return ''.join(uuid)
def get_algo(ai):
fp = js.call('generateVisitKey')
localTk = js.call("localTk", fp)
expandParams = js.call('expandParams', ai, fp)
headers = {
"authority": "cactus.jd.com",
"accept": "application/json",
"content-type": "application/json",
"referer": "https://search.jd.com/",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
}
url = "https://cactus.jd.com/request_algo"
data = {
"version": "4.9",
"fp": fp,
"appId": ai,
"timestamp": int(time.time() * 1000),
"platform": "web",
"expandParams": expandParams,
"fv": "h5_file_v4.9.1",
"localTk": localTk
}
data = json.dumps(data, separators=(',', ':'))
response = requests.post(url, headers=headers, data=data).json()
tk = response["data"]["result"]["tk"]
algo = response["data"]["result"]["algo"]
rd = re.findall("rd='(.*?)';", algo)[0]
algo = re.findall(r"algo\.(.*?)\(", algo)[0]
return fp, algo, tk, rd
def get_price(sku):
api_appid = 'fb5df'
# fp, algo, tk, rd = get_algo(api_appid)
# logger.debug(f"{api_appid} fp:{fp} algo:{algo} tk:{tk} rd:{rd}")
fp = "ccsso21xkrcdsso4"
algo = "MD5"
tk = "tk03wb29d1c3818nbBzsTa1fMY0YpJ-a1oVdzNECsY-6qpvJOazfg8PX89fpcfliGs5xSd81_dHpGCY3wdXM8tk1GaAT"
rd = "3nPfbbv0qakI"
ts = str(int(time.time() * 1000))
headers = {
"authority": "api.m.jd.com",
"accept": "application/json, text/javascript, */*; q=0.01",
"referer": "https://item.jd.com/",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"x-referer-page": "https://item.jd.com/10109684762090.html",
"x-rp-client": "h5_1.0.0"
}
##if cookie!=None:
## headers["cookie"]=cookie
cookies = {
"__jdu": "17293987875691788438336",
"areaId": "5",
"PCSYCityID": "CN_130000_130400_0",
"shshshfpa": "9a5434d1-55dc-0b17-afb7-517c7299dd2e-1729398790",
"shshshfpx": "9a5434d1-55dc-0b17-afb7-517c7299dd2e-1729398790",
"pinId": "aKKFIx5WU89-6cLG7RSx1LV9-x-f3wj7",
"pin": "jd_7d020ac3ec434",
"unick": "%E5%A6%96%E5%93%A5%E5%93%A56",
"ceshi3.com": "203",
"_tp": "S6HK9Ih%2B7UrKGpY9ovXQfMq0WHQ%2FwHGym2ktIj59trg%3D",
"_pst": "jd_7d020ac3ec434",
"source": "PC",
"platform": "pc",
"jcap_dvzw_fp": "lgBMB_apUig7S62c6AvSfP1hV5HL7Fu-cZvU37TRpJ64aiUg3IsxH4AuPAZpKuTrji0U7nguXGhlqgP0U0mNkg==",
"__jdv": "85788037%7Ciosapp%7Ct_335139774%7Cappshare%7CWxfriends_shareid101031fedc18929f26de611fe262f282c89ab92d17295286322613_shop_none%7C1729564673140",
"3AB9D23F7A4B3CSS": "jdd03FTRIVEJ57GI3RV367OZTPMDFSHECQZZQ752F5TAERK77C2FNCI6XCDDVZFB445VUAYU4A7ILASDV6TO5SQGW5TNQ5EAAAAMSWMNMGJYAAAAADXF3KQK6YPSOEUX",
"_gia_d": "1",
"thor": "8718533D55F74202EDC9C17A7E55808D7856B964B017DF0C1F2C996EFCAE2E9B487EA279BB9C4AF8627984349130413A310A59A68301703BAB5EEC08235787CFF620274881E0F6254EB4A4B396CFAD3F1AC43BC09558540E0B0ECE85645B9EC2E2C855B13AED1435DF7560BFF3C22D523D64EE3E9485520D9810315A939E3DC5F1A5E8209A25FA7D8BEC86554A81A5EDF1AC17418AF088F3655E7C54717A222F",
"light_key": "AASBKE7rOxgWQziEhC_QY6ya74pU_faxeaBQMG0ouMjvAQAf0N3WNJ56y5B2k3P51ls6dAAG",
"3AB9D23F7A4B3C9B": "FTRIVEJ57GI3RV367OZTPMDFSHECQZZQ752F5TAERK77C2FNCI6XCDDVZFB445VUAYU4A7ILASDV6TO5SQGW5TNQ5E",
"mt_xid": "V2_52007VwMUUVVaWlMZQB9YAm8DFFtUXVBTHUsebAUyV0ZbWAxVRhZBHwsZYlYRB0EIBw4bVU4MUDAKFgVbUVVSGXkaXQZiHxJTQVtRSx9NEl8HbAYVYl9oUmocSRBfAG4LFFFcUGJfHkAf",
"token": "ad66c84aac27a21c59e6c2814cf2ccb8,3,960878",
"jsavif": "1",
"__jda": "181111935.17293987875691788438336.1729398788.1729564610.1729581727.3",
"__jdb": "181111935.4.17293987875691788438336|3.1729581727",
"__jdc": "181111935",
"flash": "3_wvbkgYLTyY4F9-gCClJhlyo1Mw1QdzEbrk0lxRVQjGHxB0O1D7nYf6Y8IV02Vz6LkkRL8Q12x0YuMeVgdoadMLq4BD7dOniCaNTsUMDeUGnLsSCuvinpGoXDrM0R8i9t_bXwlNT9gDDqBmSB-6Gk3ApkTokIkmpsuDoIX7zlrxByBr8-mw32-V**",
"ipLoc-djd": "5-148-172-34120",
"shshshfpb": "BApXSFfcUsPdAoprBp5vlox1-OAvJX2z0Bmt4gL9p9xJ1MrqzCYG2"
}
url = "https://api.m.jd.com/"
body = {
"skuId": sku,
"cat": "1320,2641,2642",
"area": "5_148_172_34120",
"shopId": "12207507",
"venderId": 12518117,
"paramJson": "{\"platform2\":\"1\",\"colType\":0,\"specialAttrStr\":\"p0ppppppppppppppppppppppppp\",\"skuMarkStr\":\"00\"}",
"num": 1,
"bbTraffic": "",
"canvasType": 1,
"giftServiceIsSelected": ""
}
body = json.dumps(body, ensure_ascii=False, separators=(",", ":"))
params = {
"appid": "pc-item-soa",
"functionId": "pc_detailpage_wareBusiness",
"client": "pc",
"clientVersion": "1.0.0",
"t": ts,
"body": body,
##"x-api-eid-token": "jdd03KVN2BG6B6II3WXOWHUT4MPGOGMO3OQ5DZSTIKYF3HTHKBIBGSGGD47T45RYVHOSPZCKPB34ABDGB3YPJSTDLSRLIT4AAAAMR4V6C5XIAAAAACRGQDDWZH5LYI4X",
"x-api-eid-token": "jdd03TBT6WE4WMF4PHCAWA4ARALVIPT5OMQ4BQRGPDAYOB2FRF4ZFI7PNNNYGOIDXKB4SG6RDGIOP7TPKAXVQ3DQUEP25G4AAAAMSWKE3LNQAAAAACLVFJYDTNARXWQX",
"loginType": "3",
"scval": sku,
"uuid": "181111935.1726113890136215874918.1726113890.1726113890.1726129121.2"
}
h5st = js.call("get_H5st", body, ts, params["appid"], params["functionId"], api_appid, fp, algo, tk, rd)
params["h5st"] = h5st
logger.debug(f" H5st 结果:{h5st}")
response = requests.get(url, headers=headers, cookies=cookie, params=params)
##response = requests.get(url, headers=headers, params=params)
print(response.status_code)
logger.debug(response)
logger.debug(response.text)
# logger.info(response.json()["price"])
load_cookie()
if __name__ == "__main__":
##js = execjs.compile(open("./jd_h5st_encrypt.js", "r", encoding="utf-8").read())
skus = ['100055840709', '100021136758', '100032586491', '34533031087', '100058167024', '100082186087',
'100077587929', '100036474892', '10056013758919', '100014805124', '100009497210', '10100720343444',
'10079373721437', '58579400328', '10029555779444', '100043167344', '100020760933', '100113532463',
'10047345306664', '100042256962', '100007157415', '100006529843', '10052077917985', '100060150951',
'10053628602097', '1584883842', '10067842667839', '10026365639431', '10099221533185', '100052602673',
'10053628602097', '10085996671578', '10048614350496', '10084090773366', '569091', '100008631319',
'10087691476163', '100012886904', '10026365639431', '100014805100', '100062571977', '100123529044']
for i, sku in enumerate(skus):
logger.info(f'第============================={i}次==============================')
get_price(sku)
time.sleep(30)