一、技术要点:
1、cookie可以从手机app端用charles抓包获取;
2、无需安装nodejs,纯python源码;
3、商品详情接口为:functionId ="wareBusiness";
4、clientVersion = "10.1.4"同时也支持更高的版本;
5、sign签名算法已转成python源码;
# -*- coding: UTF-8 -*-
import requests,json
import pkgutil
import time
from urllib.parse import urlparse, parse_qs, urlunparse
import hashlib
import execjs
from urllib.parse import quote
import io
import sys
from coreMethod import service
def savetofile(text,filename):
file = open(filename, "w",encoding='utf-8' )
file.write(text)
file.close()
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
def jdsku(skuId,source_value):
body={"abTest800":True,"avoidLive":False,"brand":"Xiaomi","cityId":2258,"cpsNoTuan":None,"darkModelEnum":3,"districtId":2259,"eventId":"Searchlist_Productid","fromType":0,"isDesCbc":False,"latitude":"24.343321","lego":True,"longitude":"102.548038","model":"MI+4LTE","ocrFlag":False,"pluginVersion":101040,"plusClickCount":0,"plusLandedFatigue":0,"provinceId":"25","skuId":skuId,"source_type":"search","source_value":source_value,"townId":57314,"uAddrId":"0","utmMedium":None}
data_json = json.dumps(body, ensure_ascii=False, separators=(",", ":"))
data="body="+quote(data_json)+"&"
data_len=len(data)
print(data_len)
functionId ="wareBusiness"
uuid="d5aada6c69ce7237" # uuid = "ZNVrYWHrDwC2EWDvDzSzDm=="
clientVersion = "10.1.4"
api_url="https://api.m.jd.com/client.action?functionId=wareBusiness&clientVersion=10.1.4&build=90060&client=android&d_brand=Xiaomi&d_model=MI4LTE&osVersion=6.0.1&screen=1920*1080&partner=ks006&oaid=&eid=eidA0c138122bas4uo1qCosmRnqrZBkTZ+zEF7qNa5UCxrzSE5IyVBHJw4jzuBKyNz0TPXE0oY0j0H/viRPJy5RUE1KWCJuMWV52ufEtPyZiLpXsetVD&sdkVersion=23&lang=zh_CN&eu=8363533373230323933313336333&fv=93D2634303938303363663032626&uuid=d5aada6c69ce7237&aid=d5aada6c69ce7237&area=25_2258_2259_57314&networkType=wifi&wifiBssid=d9077de60f51d1d1d6f228a96f318e0c&uts=0f31TVRjBSsqndu4%2FjgUPz6uymy50MQJ57QGqe4EVdPCC%2F%2BLaIc%2B0FPy%2BbUQbRC5NoDqqw5SzXn%2B5IzKEzRV7U4tEboVX3RmAjshdIn%2BrmSbjWta516veiyWgiDkt89AHGr9Rp0fcz01k8UAHnDKv9FJVcx9o%2BHKLIDKAa6QQUSBNqX7wvJlkldVcZElJ1qX8Gf%2F4RKU8CYMjipFaink5w%3D%3D&uemps=0-0&harmonyOs=0&scval=10053586372378";
sign=service.get_st_sign_sv(data_json, functionId, uuid, clientVersion)
# print('技术支持:复制:byc6352')
api_url=api_url+'&'+sign
real_url = api_url.replace("https://api.m.jd.com", "")
print(real_url)
# print(data_json)
# data_url=quote(data_json)
# print(data_url)
headers={
"method":"POST",
"path": real_url,
"scheme": "https",
"charset": "UTF-8",
"jdc-backup": 'pin=jd_eiFeOmfKYTrp;wskey=AAJk-9PXAEDx4VigFTYENYvbbF_ih0fwKNPxtlGjLBxeKZDIHTo0dlOGi9kthRmaIPxAQc8LOjXjivrJlZRmTDk92_7gn7xD;whwswswws=AAo0qnXeKECW5dHtHD2SyG-aA65Td2U3WT7WUwAAAAAA;unionwsws={"devicefinger":"eidA0c138122bas4uo1qCosmRnqrZBkTZ+zEF7qNa5UCxrzSE5IyVBHJw4jzuBKyNz0TPXE0oY0j0H\/viRPJy5RUE1KWCJuMWV52ufEtPyZiLpXsetVD","jmafinger":"AAo0qnXeKECW5dHtHD2SyG-aA65Td2U3WT7WUwAAAAAA"};',
"Authority": "api.m.jd.com",
"Accept": "*/*",
# "Accept-Encoding": "br,gzip,deflate",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cookie": 'pin=jd_LStcEbIzGjuR;wskey=AAJkcwjDAECOW8kziBHNbB1cl-BdbgXIW1TU1mHHu7XkyHRHGTt36GiksxgJbLVNZ4Ni-XKKKXahMVmrVoH6IagBm2_RD_-n;whwswswws=JD012145b9Ooh6gW1WYH168526050472603eFWOcdKH3-r3FyvX7W1dFwIKf7xAscQeSZ4_zhAV07wcda_pYWPbGQW_fnTydijhfpLKLUlVzIXVOor8dB-N7vkfs3rWJTxi0p1xghd~lnPHS6M-VPm1DZUIGaKbW62XTKAcWHCstLD9GZCUslR9H9xVy8TeBaMkOHcMNNOZ-86d4vztzqMQD2jeEoOoHmHbOUCNqSQL3MKF19Ct66wbQf3UlOZ7A9SdiTCPFifNr5Fwf7rWgoO2rnN4XQXFJ-YkcJvtdXPQ11I6r3V44VJc;unionwsws={"devicefinger":"eidAe50181223cs8uIOuW0dWRka9iu\/jXMDOK7iDr+Oor0tc4JwaCNymIsN1KVlEBsjUDXYycNGHW5iEV8gds4\/u1TN0isUUwp8eUG+Fk\/pxSMrh\/flR","jmafinger":"JD012145b9Ooh6gW1WYH168526050472603eFWOcdKH3-r3FyvX7W1dFwIKf7xAscQeSZ4_zhAV07wcda_pYWPbGQW_fnTydijhfpLKLUlVzIXVOor8dB-N7vkfs3rWJTxi0p1xghd~lnPHS6M-VPm1DZUIGaKbW62XTKAcWHCstLD9GZCUslR9H9xVy8TeBaMkOHcMNNOZ-86d4vztzqMQD2jeEoOoHmHbOUCNqSQL3MKF19Ct66wbQf3UlOZ7A9SdiTCPFifNr5Fwf7rWgoO2rnN4XQXFJ-YkcJvtdXPQ11I6r3V44VJc"};',
"cache-control": "no-cache",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"content-length": str(data_len),
"user-agent": "okhttp/3.12.1;jdmall;android;version/10.1.4;build/90060;screen/1080x1920;os/6.0.1;network/wifi;",
}
# body.encode(encoding='utf-8')
res=requests.post(url=api_url, headers=headers,data=data)
print(res)
text=res.text
savetofile(text,"data.txt")
print(text)
return text
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('jd app商品详情。技术支持:v~+:byc6352;QQ:39848872')
skuId = "10053586372378" # skuId 为商品ID
source_value="小学生书包" # source_value为搜索接口的关键词
jdsku(skuId,source_value)