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

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

相关推荐
DONG91315 分钟前
《三驾马车:MySQL、MongoDB、Redis对比与融合实战》
数据库·redis·sql·mysql·mongodb·database
360安全应急响应中心17 分钟前
Python代码保护之重置操作码映射的攻与防探究(一)
python·逆向
码界奇点39 分钟前
Python内置函数全解析:30个核心函数语法、案例与最佳实践指南
linux·服务器·python
程序边界40 分钟前
从 Oracle 到 KingbaseES:企业信创改造的“抄作业”模板,直接套用!
数据库·oracle
funfan05171 小时前
奇怪的“bug”--数据库的“隐式转换”行为
数据库·bug
dreams_dream1 小时前
django错误记录
后端·python·django
Jasonakeke1 小时前
【重学MySQL】八十八、8.0版本核心新特性全解析
android·数据库·mysql
comeoffbest1 小时前
PostgreSQL 能存万物:从安装到高级功能实战
数据库·postgresql
MC皮蛋侠客1 小时前
使用Python实现DLT645-2007智能电表协议
python·网络协议·tcp/ip·能源
时序数据说2 小时前
IoTDB如何解决海量数据存储难题?
大数据·数据库·物联网·时序数据库·iotdb