虾皮(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

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

相关推荐
郝YH是人间理想42 分钟前
Python面向对象
开发语言·python·面向对象
藍海琴泉43 分钟前
蓝桥杯算法精讲:二分查找实战与变种解析
python·算法
Full Stack Developme2 小时前
SQL 版本历史
数据库·sql
惜棠4 小时前
ragflow安装es报错怎么办
大数据·elasticsearch·搜索引擎
杰克逊的日记4 小时前
mysql数据实时全量+增量迁移
数据库·mysql·数据迁移
linuxxx1105 小时前
centos7 升级MariaDB 到 10.5 或更高版本
数据库·mariadb
mqwguardain5 小时前
python常见反爬思路详解
开发语言·python
换个网名有点难5 小时前
django怎么配置404和500
数据库·django
_庄@雅@丽5 小时前
(UI自动化测试web端)第二篇:元素定位的方法_xpath扩展(工作当中用的比较多)
python·ui自动化元素定位·xpath元素定位
Adellle6 小时前
MySQL
数据库·后端·mysql