mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-22 14:48:13 +02:00
feat: Implement improved search service with persistent browser and modular site-specific parsers, including Gifi.
This commit is contained in:
1 parent
64067347d1
commit
4720ed6b93
4 files changed
+203
-120
No files matched your search
+35
-38
@@ -1,53 +1,50 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from playwright.async_api import async_playwright
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add project root to path
|
||||
sys.path.append(os.getcwd())
|
||||
|
||||
from app.services.improved_search_service import ImprovedSearchService
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
async def debug_gifi():
|
||||
url = "https://www.gifi.fr/catalogsearch/result/?q=lutin"
|
||||
print("Initializing search service...")
|
||||
await ImprovedSearchService.initialize()
|
||||
|
||||
async with async_playwright() as p:
|
||||
browser = await p.chromium.launch(headless=True)
|
||||
page = await browser.new_page()
|
||||
try:
|
||||
print("Searching Gifi for 'chaise'...")
|
||||
results = await ImprovedSearchService.search_site("gifi.fr", "chaise")
|
||||
|
||||
logger.info(f"Navigating to {url}...")
|
||||
await page.goto(url, timeout=60000)
|
||||
print(f"\nFound {len(results)} results.")
|
||||
|
||||
# Wait for results
|
||||
try:
|
||||
await page.wait_for_selector(".products-grid, .product-items, .search-results, .products", timeout=10000)
|
||||
logger.info("Results container found.")
|
||||
except:
|
||||
logger.warning("Results container NOT found (timeout).")
|
||||
if results:
|
||||
print("\n--- First 5 Results ---")
|
||||
for i, res in enumerate(results[:5]):
|
||||
print(f"\nItem {i+1}:")
|
||||
print(f" Title: {res.title}")
|
||||
print(f" Price: {res.price} {res.currency}")
|
||||
print(f" Image: {res.image_url}")
|
||||
print(f" URL: {res.url}")
|
||||
print(f" In Stock: {res.in_stock}")
|
||||
|
||||
# Check for missing critical data
|
||||
missing_price = sum(1 for r in results if r.price is None)
|
||||
missing_image = sum(1 for r in results if not r.image_url)
|
||||
|
||||
# Get all links matching the current selector
|
||||
selector = ".product-item a.product-item-link, .product-item-info a, .product-item a, .products-grid a, a[href$='.html']"
|
||||
|
||||
# Let's try to be more specific and see what we get with different parts of the selector
|
||||
|
||||
# 1. Current full selector
|
||||
elements = await page.query_selector_all(selector)
|
||||
logger.info(f"Found {len(elements)} elements with current selector.")
|
||||
|
||||
for i, el in enumerate(elements[:10]):
|
||||
href = await el.get_attribute("href")
|
||||
text = await el.inner_text()
|
||||
logger.info(f"Link {i}: {href} | Text: {text.strip()[:50]}")
|
||||
|
||||
# 2. Try to find product specific classes
|
||||
logger.info("--- Inspecting specific product classes ---")
|
||||
product_items = await page.query_selector_all(".product-item")
|
||||
logger.info(f"Found {len(product_items)} .product-item elements")
|
||||
|
||||
if product_items:
|
||||
first_item = product_items[0]
|
||||
html = await first_item.inner_html()
|
||||
logger.info(f"First product item HTML snippet: {html[:500]}")
|
||||
|
||||
await browser.close()
|
||||
print(f"\nStats:")
|
||||
print(f" Total: {len(results)}")
|
||||
print(f" Missing Price: {missing_price}")
|
||||
print(f" Missing Image: {missing_image}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error: {e}", exc_info=True)
|
||||
finally:
|
||||
await ImprovedSearchService.shutdown()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(debug_gifi())
|
||||
Reference in new issue
Block a user