Shopee 是东南亚及中国台湾地区的跨境电商平台,其开放平台(Shopee Open API)为开发者提供了一系列接口,用于获取商品数据、管理店铺、处理订单等操作。商品列表 API 是其中核心接口之一,主要用于获取店铺内商品信息或搜索平台上的商品数据,适用于开发者构建商品管理系统、数据分析工具或第三方应用。
二、商品列表 API 核心功能
- 按店铺获取商品列表
接口用途:获取指定店铺下的所有商品信息,支持分页查询。
典型参数:
shop_id:目标店铺 ID(必填)。
offset:分页偏移量(默认 0)。
limit:每页返回结果数(默认 50,最大值 200)。
status:商品状态(如在售、下架、草稿等)。 - 搜索平台商品
接口用途:根据关键词、类目、价格区间等条件搜索平台内的商品。
典型参数:
keyword:搜索关键词(如 “手机”“T 恤”)。
category_id:类目 ID(可通过 Shopee 类目 API 获取)。
price_min/price_max:价格范围。
sort_by:排序方式(如按销量、价格、新品排序)。
应用场景:
比价工具:抓取同类商品价格及销量数据。
选品分析:分析热门类目下的商品趋势。 - Python请求示例
import requests
import json
# 假设API封装接口地址
API url=c0b.cc/R4rbK2 wechat id:Taobaoapi2014
def get_shopee_products(shop_id, api_key, country, limit=10, page=1):
headers = {
'X-ShopID': shop_id,
'X-API-KEY': api_key,
'Content-Type': 'application/json'
}
params = {
'country': country,
'limit': limit,
'page': page,
'by': 'popularity', # 可以根据需要修改排序方式,如'popularity', 'price_asc', 'price_desc'等
}
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
data = response.json()
return data['items'] # 返回商品列表
else:
print(f"Error: {response.status_code}")
return None
# 使用示例
shop_id = 'your_shop_id'
api_key = 'your_api_key'
country = 'TW' # 国家代码,例如台湾是TW,马来西亚是MY等
products = get_shopee_products(shop_id, api_key, country)
if products:
for product in products:
print(product['name'], product['price']) # 打印商品名称和价格
通过以上步骤,你应该能够使用Python成功调用Shopee的商品列表API并获取所需的数据。