From 9c5a85c5891a08100593a7661d0eaa921065f50a Mon Sep 17 00:00:00 2001 From: furkanyigit34 <134547018+furkanyigit34@users.noreply.github.com> Date: Thu, 13 Aug 2026 18:34:59 +0300 Subject: [PATCH] fix(scraper): best seller siralamasi, tekrar eden urunler ve sosyal kanit bugu duzeltildi Ne yaptik: - scraper.py fetch_page: "sst": "BEST_SELLER" parametresi eklendi - scraper.py fetch_page: "countryCode": "TR" parametresi eklendi - scraper.py _normalize_search_product: socialProof (TEKIL) alanindan okunuyor, eski cogul socialProofs fallback olarak birakildi - main.py _find_leaves: pathModel artik "-x-c" formatinda uretiliyor (queue_worker.py ile ayni mantik) Neden yaptik: - Trendyol Search API siralama parametresi verilmezse sayfalar arasi tutarsiz sonuc donuyordu: 240 urunluk cekimde sadece 134 benzersiz urun geliyordu, yani raporlarin %44'u ayni urunun tekrariydi. sst=BEST_SELLER ile tekrar tamamen sifirlandi (240/240 benzersiz) - Sosyal kanit alani API'de TEKIL "socialProof" olarak geliyor ama kod cogul "socialProofs" diye okuyordu; bu yuzden satis/favori verisi hep bos donuyordu. Telafi icin cagrilan Top Rankings API ise Trendyol tarafinda kaldirildigi icin 404 veriyor (K8s loglarinda dogrulandi). Duzeltmeden sonra 238/240 uruna orderCount ve favoriteCount geliyor - countryCode zorunlu hale gelmis; yoksa API 400 "Required country information" donuyor - main.py salt slug gonderiyordu (or. "yuz-kremi"), API 0 urun donuyordu. Dogru format "yuz-kremi-x-c1122" Test: - yuz-kremi-x-c1122, 10 sayfa: 240 urun / 240 benzersiz / 0 tekrar / 238 sosyal kanit - Regresyon: 6 farkli kategori tipinde 6/6 basarili, tekrar yok Co-Authored-By: Claude Opus 5 (1M context) --- backend/main.py | 5 ++++- backend/scraper.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/backend/main.py b/backend/main.py index d69bf51..8c21a4d 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1694,7 +1694,10 @@ async def create_report( # This is a leaf — return itself cat = tree_by_id.get(parent_id) if cat: - path_model = (cat.get("url") or "").lstrip("/") or None + # Trendyol pathModel formati: "-x-c" (or. yuz-kremi-x-c1122). + # Salt slug gonderilirse API 0 urun donuyor. queue_worker.py ile ayni mantik. + url_slug = (cat.get("url") or "").lstrip("/") + path_model = f"{url_slug}-x-c{cat['id']}" if url_slug else None return [(path_model, cat["name"], cat["id"])] return [] leaves = [] diff --git a/backend/scraper.py b/backend/scraper.py index 6e7801e..bbc2abc 100644 --- a/backend/scraper.py +++ b/backend/scraper.py @@ -186,6 +186,12 @@ class TrendyolSearchScraper: "pathModel": self.path_model, "pi": page, "ps": self.page_size, + # sst=BEST_SELLER: Trendyol'un cok satan siralamasi. Siralama parametresi + # verilmezse API sayfalar arasi tutarsiz sonuc donuyor — ayni urun farkli + # sayfalarda tekrar ediyor (240 urunluk cekimde ~%44 tekrar olctuk). + "sst": "BEST_SELLER", + # countryCode zorunlu oldu; yoksa API 400 "Required country information" doner + "countryCode": "TR", "channelId": 1, "storefrontId": 1, "culture": "tr-TR" @@ -264,7 +270,10 @@ def _normalize_search_product(raw: dict) -> dict: "imageUrl": raw.get("image", raw.get("imageUrl", "")), "merchantListings": raw.get("merchantListings", []), "winnerVariant": raw.get("winnerVariant", {}), - "socialProofs": raw.get("socialProofs", []), + # Search API alani TEKIL "socialProof" — cogul "socialProofs" diye okundugu icin + # bugune kadar hep bos donuyordu. Ic format cogul kaliyor (downstream kod ona bagli). + # Icerik: [{"key":"orderCount","value":"3000+"},{"key":"favoriteCount","value":"2M"}] + "socialProofs": raw.get("socialProof") or raw.get("socialProofs") or [], "categoryId": raw.get("categoryId"), "categoryName": raw.get("categoryName"), }