首页 > 大数据 > 数据分析 > 一键式商品信息获取:京东API返回值深度挖掘
一、API返回值核心字段解析
以
item_get接口为例,其返回的JSON数据包含以下关键字段:
skuId:商品唯一标识符,用于精准定位商品变体(如不同颜色、尺寸)。name/
title:商品名称,通常包含品牌、型号、核心卖点(如“华为Mate 60 Pro 5G手机 12GB+512GB 雅丹黑”)。price/
promotionPrice:当前售价与促销价,支持动态定价策略分析。stock:库存数量(部分接口返回模糊值,如“100+”),可结合销量预测库存周转率。saleNum:商品销量(累计或近30天),用于评估市场热度与竞品对比。commentCount/
goodCommentCount:评价总数与好评数,结合
score字段可计算好评率,辅助口碑管理。couponInfo:优惠券信息(如“满1000减50”),支持促销活动效果追踪。desc:商品详情页HTML代码,包含规格参数、包装清单等结构化文本,可通过正则表达式提取关键信息。imageUrl:主图与轮播图URL,支持图片下载与自动化上架流程。videoUrl:商品视频链接(部分接口返回),可用于丰富商品展示形式。deliveryInfo:配送范围、时效(如“次日达”)、运费模板,优化物流成本计算。afterSaleService:退换货政策、保修期限,提升用户购物信任度。pythonimport requestsdef get_competitor_price(item_id):url = f"https://api-gw.onebound.cn/jd/item_get/?key=YOUR_APP_KEY&secret=YOUR_SECRET_KEY&num_iid={item_id}"response = requests.get(url).json()price = response['item']['price']promotion_price = response['item'].get('promotionPrice', price)return promotion_price if promotion_price < price else price# 示例:获取商品ID为100061393554的最低、价lowest_price = get_competitor_price("100061393554")print(f"最低售价: {lowest_price}元")pythondef analyze_hot_items(keyword, page_size=10):url = f"https://api-gw.onebound.cn/jd/item_search/?key=YOUR_APP_KEY&secret=YOUR_SECRET_KEY&q={keyword}&page_size={page_size}"response = requests.get(url).json()hot_items = []for item in response['result']:sale_num = int(item['saleNum'])comment_ratio = int(item['goodCommentCount']) / max(1, int(item['commentCount']))if sale_num > 1000 and comment_ratio > 0.9: # 筛选高销量、高好评商品hot_items.append({'name': item['title'],'price': item['price'],'stock': item.get('stock', '未知')})return hot_items# 示例:搜索“运动鞋”并筛选热门商品hot_shoes = analyze_hot_items("运动鞋")for shoe in hot_shoes:print(f"{shoe['name']} | 价格: {shoe['price']}元 | 库存: {shoe['stock']}")snownlp):
pythonfrom snownlp import SnowNLPdef analyze_comments(item_id):url = f"https://api-gw.onebound.cn/jd/item_get_comment/?key=YOUR_APP_KEY&secret=YOUR_SECRET_KEY&num_iid={item_id}"response = requests.get(url).json()comments = response['comments']sentiment_scores = []for comment in comments:s = SnowNLP(comment['content'])sentiment_scores.append(s.sentiments) # 情感分数(0-1,越接近1越积极)avg_score = sum(sentiment_scores) / len(sentiment_scores)return avg_score# 示例:分析商品ID为100061393554的评价情感sentiment = analyze_comments("100061393554")print(f"用户评价平均情感分数: {sentiment:.2f}")随着京东开放平台生态的完善,API返回值将进一步丰富,例如:
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70046834/viewspace-3093328/ ,如需转载,请注明出处,否则将追究法律责任。