mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-20 21:58:49 +02:00
Merge pull request #215 from R0m1k3/antigravity
feat: Increase Amazon limit to 50 and fix screenshot framing
This commit is contained in:
4 files changed
+33
-8
No files matched your search
@@ -31,7 +31,7 @@ class AmazonSearchProgress(BaseModel):
|
|||||||
@router.get("/search")
|
@router.get("/search")
|
||||||
async def search_amazon(
|
async def search_amazon(
|
||||||
q: str = Query(..., min_length=1, description="Terme de recherche"),
|
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.
|
Recherche de produits sur Amazon France.
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ class AmazonScraperService:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@classmethod
|
@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
|
Scrape Amazon France search results
|
||||||
|
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ class TrackingScraperService:
|
|||||||
if selector:
|
if selector:
|
||||||
await TrackingScraperService._wait_for_selector(page, selector)
|
await TrackingScraperService._wait_for_selector(page, selector)
|
||||||
else:
|
else:
|
||||||
await TrackingScraperService._auto_detect_price(page)
|
await TrackingScraperService._auto_detect_price(page, url)
|
||||||
|
|
||||||
if config.smart_scroll:
|
if config.smart_scroll:
|
||||||
await TrackingScraperService._smart_scroll(page, scroll_pixels)
|
await TrackingScraperService._smart_scroll(page, scroll_pixels)
|
||||||
@@ -336,8 +336,33 @@ class TrackingScraperService:
|
|||||||
logger.warning(f"Selector {selector} not found or timed out: {e}")
|
logger.warning(f"Selector {selector} not found or timed out: {e}")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def _auto_detect_price(page: Page):
|
async def _auto_detect_price(page: Page, url: str = ""):
|
||||||
logger.info("No selector provided. Attempting to find price element...")
|
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:
|
try:
|
||||||
price_locator = page.locator("text=/$[0-9,]+(\\.[0-9]{2})?/")
|
price_locator = page.locator("text=/$[0-9,]+(\\.[0-9]{2})?/")
|
||||||
if await price_locator.count() > 0:
|
if await price_locator.count() > 0:
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export default function AmazonSearch() {
|
|||||||
// Construire l'URL avec les paramètres
|
// Construire l'URL avec les paramètres
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
q: query.trim(),
|
q: query.trim(),
|
||||||
max_results: 20,
|
max_results: 50,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Créer l'EventSource pour SSE
|
// Créer l'EventSource pour SSE
|
||||||
@@ -103,8 +103,8 @@ export default function AmazonSearch() {
|
|||||||
<Star
|
<Star
|
||||||
key={i}
|
key={i}
|
||||||
className={`h-4 w-4 ${i < Math.floor(rating)
|
className={`h-4 w-4 ${i < Math.floor(rating)
|
||||||
? 'fill-yellow-400 text-yellow-400'
|
? 'fill-yellow-400 text-yellow-400'
|
||||||
: 'text-gray-300'
|
: 'text-gray-300'
|
||||||
}`}
|
}`}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Reference in new issue
Block a user