×

Ozon关键词搜索接口:参数合规限流与搜索权重降噪实战方案

Ace Ace 发表于2026-09-15 17:41:44 浏览15 评论0

抢沙发发表评论

Ozon Seller 关键词搜索接口是俄系跨境平台选品、竞品监控、关键词排名收录统计的核心数据源。现有公开教程大多只实现基础POST请求调用,忽略平台专属特性:俄语关键词编码适配、单页条数硬限制、高频请求限流、搜索权重浮动导致的跨页重复商品、无库存占位脏数据等生产问题。本文跳出入门演示思路,聚焦接口参数规范化、请求频率可控、结果去重降噪、字段归一化,提供一套适配批量定时采集的稳定落地代码。
Ozon接口不同于常规电商接口,对请求频率、参数格式校验严格,批量翻页极易触发限流,且搜索排序动态刷新,单纯循环分页会产生大量冗余重复数据,严重影响数据分析准确性。

点击获取key和secret
一、生产级完整实现代码

import requests
import time

class OzonKeywordSearch:
    def __init__(self, api_key, client_id):
        self.api_key = api_key
        self.client_id = client_id
        self.base_url = "https://api.ozon.ru/v2/product/search"
        self.unique_oid = set()
        # 限流阈值,贴合平台安全频率
        self.rate_limit_sleep = 0.3

    def search(self, keyword, page=1, page_size=50, sort="relevance"):
        # 平台硬参校验:单页最大50条
        page_size = min(page_size, 50)
        headers = {
            "Api-Key": self.api_key,
            "Client-Id": self.client_id,
            "Content-Type": "application/json"
        }
        payload = {
            "text": keyword,
            "page": page,
            "page_size": page_size,
            "sort_by": sort
        }
        try:
            resp = requests.post(self.base_url, json=payload, headers=headers, timeout=20)
            resp.raise_for_status()
            res_data = resp.json()
            time.sleep(self.rate_limit_sleep)
        except Exception as e:
            return {"success": False, "msg": f"请求异常:{str(e)}", "data": []}

        result_list = res_data.get("result", {}).get("items", [])
        clean_data = []
        for item in result_list:
            oid = item.get("product_id")
            # 全局去重 + 过滤无库存无效商品
            if not oid or oid in self.unique_oid or int(item.get("stock", 0)) <= 0:
                continue
            self.unique_oid.add(oid)
            clean_data.append({
                "product_id": oid,
                "title": item.get("name", "").strip(),
                "price": float(item.get("price", 0)),
                "old_price": float(item.get("old_price", 0)) if item.get("old_price") else 0,
                "stock": item.get("stock", 0),
                "category_id": item.get("category_id", 0)
            })
        return {"success": True, "total": res_data.get("result", {}).get("total", 0), "data": clean_data}

if __name__ == "__main__":
    client = OzonKeywordSearch("你的Api-Key", "你的Client-Id")
    # 支持俄语关键词直接传入
    ret = client.search("наушники", page=1)
    print("清洗后有效商品数据:", ret["data"])


二、差异化核心优化点
1. 平台参数强合规:强制限制单页最大50条,贴合Ozon官方参数约束,杜绝参数超限导致的返回空数据或报错。
2. 可控限流机制:内置短延时休眠,适配平台请求频率规则,避免批量翻页触发接口限流封禁,保障定时任务稳定运行。
3. 权重去重降噪:利用商品唯一ID全局去重,解决Ozon搜索权重动态刷新导致的跨页商品重复问题,保证数据唯一性。
4. 脏数据精准过滤:自动剔除零库存占位商品,统一新旧价格字段结构,适配价格波动、促销数据分析场景。
三、线上对接避坑要点
Ozon搜索接口优先适配俄语关键词,中文关键词检索命中率极低,业务端需统一使用俄语词库。接口无无限分页能力,深度分页数据权重失真,无需全量翻页。鉴权依赖固定请求头,Api-Key与Client-Id缺一不可,参数错误直接返回空结果。批量任务需分级控频,核心关键词低频轮询,减少无效请求消耗。

群贤毕至

访客