京东商品历史价格API接口(如
item_history_price)的调用需通过京东开放平台完成,以下是核心参数讲解及操作指南:
AppKey和
AppSecret(用于身份验证)。num_iid:商品ID(如
100033966459),唯一标识商品。app_key:开发者应用的AppKey。method:接口方法名(如
jd.item_history_price)。timestamp:请求时间戳(秒级)。sign:签名(通过
AppSecret对参数排序后生成,防篡改)。start_date/
end_date:查询时间范围(默认近30天)。region:地区编码(如北京
1,上海
2),用于区域价差分析。json{ "items": { "num_iid": "63153022346", "title": "安踏女鞋跑步鞋", "detail_url": "https://item.jd.com/63153022346.html", "lower_price": 159.01, "lower_date": "2021-02-24", "current_price": 169.00, "item": [ {"date": "2021-02-24", "price": 159.01, "discount": "满减"}, {"date": "2021-02-25", "price": 159.01, "discount": ""} ] }, "error": "", "error_code": "0000", "api_info": "today:15 max:10000", "execution_time": 0.682}
items.item:历史价格数组,含日期、价格、折扣信息。lower_price/
lower_date:历史低价及对应日期。error_code:
0000表示成功,其他代码需参考错误文档。pythonimport requestsimport hmacimport hashlibimport jsonfrom datetime import datetimedef generate_sign(secret, params): sorted_params = sorted(params.items()) query_string = ''.join(f'{k}{v}' for k, v in sorted_params) return hmac.new(secret.encode(), query_string.encode(), hashlib.sha256).hexdigest().upper()# 配置参数app_key = "YOUR_APP_KEY"app_secret = "YOUR_APP_SECRET"url = "https://api.jd.com/routerjson"params = { "method": "jd.item_history_price", "app_key": app_key, "timestamp": str(int(datetime.now().timestamp())), "num_iid": "100033966459", "param_json": json.dumps({"start_date": "2025-01-01", "end_date": "2025-12-25"})}params["sign"] = generate_sign(app_secret, params)# 发送请求response = requests.get(url, params=params)data = response.json()# 解析结果if data.get("error_code") == "0000": price_history = data["items"]["item"] for record in price_history: print(f"日期: {record['date']}, 价格: {record['price']}, 折扣: {record.get('discount', '')}")else: print(f"请求失败: {data.get('reason', '未知错误')}")
region参数。签名错误(1001)、
参数缺失(1002)等异常,重试时采用指数退避策略。通过上述步骤,可批量获取京东商品历史价格,并分析价格趋势、制定定价策略。如需进一步处理数据(如可视化),可使用
matplotlib生成折线图,或存储到MySQL数据库进行长期分析。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70046834/viewspace-3106220/ ,如需转载,请注明出处,否则将追究法律责任。