前言
简洁可直接使用,适配跨境电商商品同步、数据分析、铺货上货场景。
一、校验核心要点
- 返回 JSON 结构完整正常
- 商品 ID(productId)有效
- 标题不为空、长度合理
- 价格合法(大于 0)
- 主图链接有效
- 库存、类目、商家信息完整
- 过滤异常值、空数据、格式错误
二、Python 校验代码(直接可用)
python
运行
def check_aliexpress_item_accuracy(json_data): try: # 1. 检查根结构 if "result" not in json_data: return False, "返回结构异常,无 result 节点" result = json_data["result"] if not result: return False, "未获取到商品信息" # 2. 商品ID校验 product_id = result.get("productId") if not product_id or not str(product_id).isdigit(): return False, f"商品ID无效:{product_id}" # 3. 标题校验 title = result.get("subject") if not title or len(title) < 5: return False, "商品标题过短或为空" # 4. 价格校验 price = result.get("price", "0") try: price_val = float(price) if price_val <= 0: return False, f"价格异常:{price}" except: return False, "价格格式错误" # 5. 主图链接校验 img_url = result.get("imageURL") if not img_url or "http" not in img_url: return False, "商品主图无效" # 6. 库存校验 stock = result.get("stock", 0) try: if int(stock) < 0: return False, "库存不能为负数" except: pass # 7. 店铺/卖家信息 seller = result.get("sellerName") if not seller: return False, "卖家信息缺失" return True, "速卖通商品数据校验通过" except Exception as e: return False, f"校验异常:{str(e)}"
三、速卖通商品详情 API 标准 JSON 返回参考
json
{ "result": { "productId": "100500123456789", "subject": "Wireless Bluetooth Earbuds Mini Headphones", "price": "15.99", "currency": "USD", "imageURL": "https://ae01.alicdn.com/kf/xxx.jpg", "stock": 1500, "categoryId": 50909001, "sellerName": "Official Store", "detailUrl": "https://www.aliexpress.com/item/xxx.html" }, "code": 200, "success": true }
四、使用示例
python
运行
# 调用速卖通API获取json json_result = requests.get(api_url, params=params).json() # 校验 ok, msg = check_aliexpress_item_accuracy(json_result) print(ok, msg)
五、一句话总结
结构完整 + 字段合法 + 数值有效,确保商品搬家、数据分析、铺货上货稳定不出错。