Merge pull request #215 from R0m1k3/antigravity

feat: Increase Amazon limit to 50 and fix screenshot framing
This commit is contained in:
LogiFlow authored and GitHub committed 2025-12-01 16:19:45 +01:00
commit f47ceec1bf
4 files changed
+33 -8

No files matched your search

+1 -1
View File
@@ -31,7 +31,7 @@ class AmazonSearchProgress(BaseModel):
@router.get("/search")
async def search_amazon(
q: str = Query(..., min_length=1, description="Terme de recherche"),
max_results: int = Query(20, ge=1, le=50, description="Nombre max de résultats"),
max_results: int = Query(50, ge=1, le=100, description="Nombre max de résultats"),
):
"""
Recherche de produits sur Amazon France.
+1 -1
View File
@@ -277,7 +277,7 @@ class AmazonScraperService:
pass
@classmethod
async def scrape_search(cls, query: str, max_results: int = 20) -> list[AmazonProduct]:
async def scrape_search(cls, query: str, max_results: int = 50) -> list[AmazonProduct]:
"""
Scrape Amazon France search results
+28 -3
View File
@@ -175,7 +175,7 @@ class TrackingScraperService:
if selector:
await TrackingScraperService._wait_for_selector(page, selector)
else:
await TrackingScraperService._auto_detect_price(page)
await TrackingScraperService._auto_detect_price(page, url)
if config.smart_scroll:
await TrackingScraperService._smart_scroll(page, scroll_pixels)
@@ -336,8 +336,33 @@ class TrackingScraperService:
logger.warning(f"Selector {selector} not found or timed out: {e}")
@staticmethod
async def _auto_detect_price(page: Page):
logger.info("No selector provided. Attempting to find price element...")
async def _auto_detect_price(page: Page, url: str = ""):
logger.info("No selector provided. Attempting to find product area...")
# Amazon-specific handling to ensure we capture the product, not reviews
if "amazon" in url.lower():
logger.info("🛒 Amazon detected - targeting main product area")
amazon_selectors = [
"#imgTagWrapperId", # Main image
"#main-image-container", # Main image container
"#productTitle", # Product title
"#ppd", # Product Page Desktop (main container)
"#centerCol", # Center column
]
for selector in amazon_selectors:
try:
if await page.locator(selector).count() > 0:
logger.info(f"Found Amazon product area: {selector}")
element = page.locator(selector).first
await element.scroll_into_view_if_needed()
# Scroll up a bit to ensure header is visible/good framing
await page.evaluate("window.scrollBy(0, -100)")
return
except Exception:
pass
# Generic fallback: look for price
try:
price_locator = page.locator("text=/$[0-9,]+(\\.[0-9]{2})?/")
if await price_locator.count() > 0:
+3 -3
View File
@@ -37,7 +37,7 @@ export default function AmazonSearch() {
// Construire l'URL avec les paramètres
const params = new URLSearchParams({
q: query.trim(),
max_results: 20,
max_results: 50,
});
// Créer l'EventSource pour SSE
@@ -103,8 +103,8 @@ export default function AmazonSearch() {
<Star
key={i}
className={`h-4 w-4 ${i < Math.floor(rating)
? 'fill-yellow-400 text-yellow-400'
: 'text-gray-300'
? 'fill-yellow-400 text-yellow-400'
: 'text-gray-300'
}`}
/>
))}