虾皮(Shopee)商品ID获取商品详情请求示例

通过万邦(或任何第三方工具/平台)使用虾皮(Shopee)商品ID获取商品详情,需要明确以下几点:


核心思路

  1. -可调用Shopee的 item_get 接口。

    • 需要 API Key、Shop ID、Item ID 等参数,并生成签名(签名算法需按Shopee要求实现)。
  2. 请求示例

bash 复制代码
# coding:utf-8
"""
Compatible for python2.x and python3.x
requirement: pip install requests
"""
from __future__ import print_function
import requests
# 请求示例 url 默认请求参数已经做URL编码
# 封装好的虾皮商品详情供应商demo url=o0b.cn/ibrad,复制链接获取测试
url = "https://api-gw.onebound.cn/shopee/item_get/?key=<[您自己的apiKey](https://o0b.cn/ibrad)>&secret=<您自己的apiSecret>&num_iid=958470529/21785867874&country=.co.th"
headers = {
    "Accept-Encoding": "gzip",
    "Connection": "close"
}
if __name__ == "__main__":
    r = requests.get(url, headers=headers)
    json_obj = r.json()
    print(json_obj)

具体步骤(响应示例)

1. 获取商品页面数据

请求参数:num_iid=958470529/21785867874&country=.co.th 。提取页面内嵌的JSON数据。

python 复制代码
{
  "items": {
    "totalpage": 31,
    "total_results": 182,
    "page_size": 6,
    "page": "1",
    "item": [
      {
        "rate_content": "Just ok. Delivery time as expected. If you're 155cm and below, this dress length will be at your calf. Size is accurate, do follow your exact measurement. Material is acceptable. ",
        "rate_date": "2020-08-27 07:48:16",
        "pics": [],
        "display_user_nick": "t*****y",
        "auction_sku": "White,M",
        "liked_count": 0,
        "video": null
      },
      {
        "rate_content": "The quality suits the price. \nFor hijabi it best to wear camisole along as it quite see through. \nPackaging is nice 👍🏽 \nReceived less than 10 days💯\n",
        "rate_date": "2020-09-08 02:58:25",
        "pics": [
          "https://cf.shopee.com.my/file/651f130eceda11f9a6e4f4b6e077ef6d",
          "https://cf.shopee.com.my/file/fc41803a377916bc2e7293cdb04e22c4"
        ],
        "display_user_nick": "eikasaleh12",
        "auction_sku": "White,M",
        "liked_count": 13,
        "video": "https://down-aka-sg.vod.susercontent.com/api/v4/11110103/mms/my_52b44f3f-9fd1-49fc-93d2-bf9a8e6d73f1_000038.default.mp4"
      },
      {
        "rate_content": "Bought on 27-8 received on 5-9. Fast delivery seller so responsive and considerate (can make offer). The dress is also true to the size chart only 1-3 cm difference so better measure first.Im 150 cm 49kg and bought size L quite regret bcs quite big on me so should measure first bcs dress not small",
        "rate_date": "2020-09-05 11:59:01",
        "pics": [
          "https://cf.shopee.com.my/file/cdfb9576b813fc03cc21641d7f527812",
          "https://cf.shopee.com.my/file/f2590e258d9b758944791dc653af8a5a",
          "https://cf.shopee.com.my/file/c53b401b8a8acc6a75ed12c55121d4a9"
        ],
        "display_user_nick": "s*****2",
        "auction_sku": "White,L",
        "liked_count": 0,
        "video": null
      },
      {
        "rate_content": "Super fast deliveryyyyyyyy!!!! The dress is so cute! So worth it with the price. Thank you seller✨✨✨✨✨✨✨✨✨",
        "rate_date": "2020-06-30 09:33:28",
        "pics": [
          "https://cf.shopee.com.my/file/55cf1a31ea3f6112758d0305a1431aa3"
        ],
        "display_user_nick": "s*****d",
        "auction_sku": "White,M",
        "liked_count": 17,
        "video": null
      },
      {
        "rate_content": "Received in good condition. Quite a nice dress, no lining inside. Quality ok for the price.",
        "rate_date": "2020-08-30 03:31:24",
        "pics": [
          "https://cf.shopee.com.my/file/d6cc92d51971c141d35c652d6630f316"
        ],
        "display_user_nick": "c*****o",
        "auction_sku": "White,M",
        "liked_count": 0,
        "video": "https://down-aka-sg.vod.susercontent.com/api/v4/11110103/mms/my_e32b2cd7-e803-4ff2-a9f6-a0f677a3378b_000039.default.mp4"
      },
      {
        "rate_content": "Berat 70++ tggi 155cm muat pakai saiz 2xl ni. Kain cntik xjarang.",
        "rate_date": "2020-09-09 07:52:41",
        "pics": [
          "https://cf.shopee.com.my/file/20423407da83eac240baa28228baf38c"
        ],
        "display_user_nick": "hmm007",
        "auction_sku": "White,2XL",
        "liked_count": 0,
        "video": null
      }
    ]
  },
  "secache": "c20d295a2be98ac77549ddc539c6ae4a",
  "secache_time": 1729758525,
  "secache_date": "2024-10-24 16:28:45",
  "translate_status": "",
  "translate_time": 0,
  "language": {
    "default_lang": "cn",
    "current_lang": "cn"
  },
  "error": "",
  "reason": "",
  "error_code": "0000",
  "cache": 0,
  "api_info": "today:44 max:10000 all[2890=44+12+2834];expires:2030-10-30",
  "execution_time": "2.048",
  "server_time": "Beijing/2024-10-24 16:28:45",
  "client_ip": "220.177.180.75",
  "call_args": {
    "num_iid": "239487269/5435412264",
    "data": ".com.my",
    "page": "1"
  },
  "api_type": "shopee",
  "translate_language": "zh-CN",
  "translate_engine": "",
  "server_memory": "3.18MB",
  "request_id": "gw-3.671a053b79091",
  "last_id": "3638202001"
}
2. 解析关键字段

从返回的JSON数据中提取核心信息:

python 复制代码
{
  "item_id": "商品ID",
  "name": "商品名称",
  "price": 价格(单位为分,需除以100000),
  "description": "商品描述",
  "images": ["图片URL列表"],
  "stock": 库存,
  "shop_info": {
    "shop_id": "店铺ID",
    "shop_name": "店铺名称"
  }
}

注意事项

  1. 异常示例
bash 复制代码
{
  "error": "item-not-found",
  "reason": "商品没找到",
  "error_code": "2000",
  "success": 0,
  "cache": 0,
  "api_info": "today:0 max:10000",
  "execution_time": 0.081,
  "server_time": "Beijing/2020-06-10 23:44:00",
  "call_args": [],
  "api_type": "shopee",
  "request_id": "1ee0ffc041242"}
  1. 动态渲染问题
    • 如果数据通过AJAX加载,需使用 SeleniumPlaywright 模拟浏览器操作:

      python 复制代码
      from selenium import webdriver
      from selenium.webdriver.chrome.options import Options
      
      def get_dynamic_page(url):
          options = Options()
          options.headless = True
          driver = webdriver.Chrome(options=options)
          driver.get(url)
          html = driver.page_source
          driver.quit()
          return html

如需进一步优化或解决具体问题(如大规模采集),请留言或私聊!

相关推荐
bestcxx27 分钟前
0.2、AI Agent 开发中 ReAct 和 MAS 的概念
人工智能·python·dify·ai agent
qq_4046433444 分钟前
MySQL中RUNCATE、DELETE、DROP 的基本介绍
数据库·mysql
fsnine1 小时前
Python Web框架对比与模型部署
开发语言·前端·python
B站计算机毕业设计之家1 小时前
深度学习实战:python动物识别分类检测系统 计算机视觉 Django框架 CNN算法 深度学习 卷积神经网络 TensorFlow 毕业设计(建议收藏)✅
python·深度学习·算法·计算机视觉·分类·毕业设计·动物识别
程序猿小D2 小时前
【完整源码+数据集+部署教程】 【运输&加载码头】仓库新卸物料检测系统源码&数据集全套:改进yolo11-DRBNCSPELAN
python·yolo·计算机视觉·目标跟踪·数据集·yolo11·仓库新卸物料检测系统
像风一样!2 小时前
MySQL数据库如何实现主从复制
数据库·mysql
大白的编程日记.2 小时前
【MySQL】数据库表的CURD(二)
android·数据库·mysql
SiYuanFeng2 小时前
《Synthetic Visual Genome》论文数据集的预处理
python·场景图
MUTA️2 小时前
python中进程和线程
python
友善的鸡蛋2 小时前
项目中执行SQL报错oracle.jdbc.OracleDatabaseException: ORA-00942: 表或视图不存在
数据库·sql·oracle