Shopee 是東南亞及中國臺灣地區(qū)的跨境電商平臺,其開放平臺(Shopee Open API)為開發(fā)者提供了一系列接口,用于獲取商品數(shù)據(jù)、管理店鋪、處理訂單等操作。商品列表 API 是其中核心接口之一,主要用于獲取店鋪內(nèi)商品信息或搜索平臺上的商品數(shù)據(jù),適用于開發(fā)者構(gòu)建商品管理系統(tǒng)、數(shù)據(jù)分析工具或第三方應(yīng)用。
二、商品列表 API 核心功能
- 按店鋪獲取商品列表
接口用途:獲取指定店鋪下的所有商品信息,支持分頁查詢。
典型參數(shù):
shop_id:目標店鋪 ID(必填)。
offset:分頁偏移量(默認 0)。
limit:每頁返回結(jié)果數(shù)(默認 50,最大值 200)。
status:商品狀態(tài)(如在售、下架、草稿等)。 - 搜索平臺商品
接口用途:根據(jù)關(guān)鍵詞、類目、價格區(qū)間等條件搜索平臺內(nèi)的商品。
典型參數(shù):
keyword:搜索關(guān)鍵詞(如 “手機”“T 恤”)。
category_id:類目 ID(可通過 Shopee 類目 API 獲?。?br>price_min/price_max:價格范圍。
sort_by:排序方式(如按銷量、價格、新品排序)。
應(yīng)用場景:
比價工具:抓取同類商品價格及銷量數(shù)據(jù)。
選品分析:分析熱門類目下的商品趨勢。 - Python請求示例
import requests
import json
# 假設(shè)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', # 可以根據(jù)需要修改排序方式,如'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']) # 打印商品名稱和價格
通過以上步驟,你應(yīng)該能夠使用Python成功調(diào)用Shopee的商品列表API并獲取所需的數(shù)據(jù)。