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

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

相关推荐
emo了小猫2 小时前
Mybatis #{} 和 ${}区别,使用场景,LIKE模糊查询避免SQL注入
数据库·sql·mysql·mybatis
程序员的世界你不懂5 小时前
Appium+python自动化(八)- 认识Appium- 下章
python·appium·自动化
恸流失5 小时前
DJango项目
后端·python·django
Julyyyyyyyyyyy6 小时前
【软件测试】web自动化:Pycharm+Selenium+Firefox(一)
python·selenium·pycharm·自动化
潘yi.7 小时前
NoSQL之Redis配置与优化
数据库·redis·nosql
zdkdchao7 小时前
hbase资源和数据权限控制
大数据·数据库·hbase
伤不起bb7 小时前
NoSQL 之 Redis 配置与优化
linux·运维·数据库·redis·nosql
leo__5207 小时前
PostgreSQL配置文件修改及启用方法
数据库·postgresql
蓝婷儿7 小时前
6个月Python学习计划 Day 15 - 函数式编程、高阶函数、生成器/迭代器
开发语言·python·学习
love530love7 小时前
【笔记】在 MSYS2(MINGW64)中正确安装 Rust
运维·开发语言·人工智能·windows·笔记·python·rust