全部
常见问题
产品动态
精选推荐

深入研究:shopee 商品详情 API 接口 Python 攻略

管理 管理 编辑 删除

一、引言

Shopee 商品详情 API 接口是用于获取 Shopee 平台上具体商品详细信息的编程接口。通过调用该接口,开发者可以获取商品的标题、价格、库存、描述、图片等多维度信息,为电商数据分析、比价工具开发、商品监控等应用场景提供数据支持。

二、接口概述

Shopee 商品详情 API 的基本信息如下:

  • 请求 URL:通常为 shopee.com.myapi/v4/item/get(以马来西亚站点为例,不同国家站点域名可能不同)
  • 请求方式:GET
  • 必要参数
    • itemid:商品 ID
    • shopid:店铺 ID
  • 认证方式:部分接口可能需要 API 密钥或访问令牌,具体取决于 Shopee 的开放策略。
  • 返回格式:JSON,包含商品详情、价格信息、促销活动、评价摘要等内容。

三、Python 请求示例

以下是一个使用 Python 请求 Shopee 商品详情 API 的示例代码:

python

import requests
import json
# 假设API封装接口地址 
API url=c0b.cc/R4rbK2  wechat id:Taobaoapi2014 
def get_shopee_item_detail(shop_id, item_id, country_code='my'):
    """
    获取Shopee平台上指定商品的详情信息
    
    参数:
    shop_id (int): 店铺ID
    item_id (int): 商品ID
    country_code (str): 国家代码,默认为马来西亚('my')
    
    返回:
    dict: 商品详情信息的JSON解析结果
    """
    # 根据国家代码选择对应的API域名
    domain_map = {
        'my': 'shopee.com.my',  # 马来西亚
        'sg': 'shopee.sg',      # 新加坡
        'id': 'shopee.co.id',   # 印尼
        'th': 'shopee.co.th',   # 泰国
        'vn': 'shopee.vn',      # 越南
        'ph': 'shopee.ph',      # 菲律宾
        'tw': 'shopee.tw'       # 台湾
    }
    
    base_domain = domain_map.get(country_code, 'shopee.com.my')
    api_url = f"https://{base_domain}/api/v4/item/get"
    
    # 设置请求头,模拟浏览器访问
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
        'Accept': 'application/json, text/plain, */*',
        'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
        'Referer': f'https://{base_domain}/',
        'Origin': f'https://{base_domain}',
        'Sec-Fetch-Site': 'same-site',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Dest': 'empty',
    }
    
    # 设置请求参数
    params = {
        'itemid': item_id,
        'shopid': shop_id,
    }
    
    try:
        # 发送请求
        response = requests.get(api_url, headers=headers, params=params)
        
        # 检查响应状态码
        if response.status_code == 200:
            # 解析JSON数据
            data = response.json()
            return data
        else:
            print(f"请求失败,状态码: {response.status_code}")
            print(f"错误信息: {response.text}")
            return None
    
    except requests.exceptions.RequestException as e:
        print(f"请求发生异常: {e}")
        return None

# 使用示例
if __name__ == "__main__":
    # 示例店铺ID和商品ID(需要替换为实际有效的ID)
    shop_id = 123456
    item_id = 7890123
    
    # 获取商品详情
    item_detail = get_shopee_item_detail(shop_id, item_id)
    
    # 打印结果
    if item_detail:
        print(f"商品标题: {item_detail.get('data', {}).get('name', '未知')}")
        print(f"商品价格: {item_detail.get('data', {}).get('price_min', '未知') / 100000}")
        print(f"库存数量: {item_detail.get('data', {}).get('stock', '未知')}")
        print(json.dumps(item_detail, indent=2, ensure_ascii=False))

注意事项

  1. API 限制:Shopee 可能对 API 调用频率有限制,建议合理控制请求频率,避免被封禁 IP。
  2. 参数获取:商品 ID 和店铺 ID 可以从商品详情页 URL 中获取,例如:shopee.com.my/Product-Name-i.123456.7890123 中的 123456 是店铺 ID,7890123 是商品 ID。
  3. 数据解析:返回的 JSON 数据结构可能较为复杂,需要根据实际需求提取所需字段。



请登录后查看

用户19970108018 最后编辑于2025-06-09 10:03:36

快捷回复
回复
回复
回复({{post_count}}) {{!is_user ? '我的回复' :'全部回复'}}
排序 默认正序 回复倒序 点赞倒序

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level }}

作者 管理员 企业

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推荐': '推荐'}}
{{item.is_suggest == 1? '取消推荐': '推荐'}}
沙发 板凳 地板 {{item.floor}}#
{{item.user_info.title || '暂无简介'}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
打赏
已打赏¥{{item.reward_price}}
{{item.like_count}}
{{item.showReply ? '取消回复' : '回复'}}
删除
回复
回复

{{itemc.user_info.nickname}}

{{itemc.user_name}}

回复 {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}
打赏
已打赏¥{{itemc.reward_price}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回复' : '回复'}}
删除
回复
回复
查看更多
打赏
已打赏¥{{reward_price}}
80
{{like_count}}
{{collect_count}}
添加回复 ({{post_count}})

相关推荐

快速安全登录

使用微信扫码登录
{{item.label}} 加精
{{item.label}} {{item.label}} 板块推荐 常见问题 产品动态 精选推荐 首页头条 首页动态 首页推荐
取 消 确 定
回复
回复
问题:
问题自动获取的帖子内容,不准确时需要手动修改. [获取答案]
答案:
提交
bug 需求 取 消 确 定
打赏金额
当前余额:¥{{rewardUserInfo.reward_price}}
{{item.price}}元
请输入 0.1-{{reward_max_price}} 范围内的数值
打赏成功
¥{{price}}
完成 确认打赏

微信登录/注册

切换手机号登录

{{ bind_phone ? '绑定手机' : '手机登录'}}

{{codeText}}
切换微信登录/注册
暂不绑定
CRMEB客服

CRMEB咨询热线 咨询热线

400-8888-794

微信扫码咨询

CRMEB开源商城下载 源码下载 CRMEB帮助文档 帮助文档
返回顶部 返回顶部
CRMEB客服