chore: sync project files
This commit is contained in:
82
test_backmarket_macbook_m3.py
Executable file
82
test_backmarket_macbook_m3.py
Executable file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Test du parser Backmarket avec un MacBook Air M3 15 pouces."""
|
||||
|
||||
from pricewatch.app.scraping.pw_fetch import fetch_playwright
|
||||
from pricewatch.app.stores.backmarket.store import BackmarketStore
|
||||
import json
|
||||
|
||||
# URL MacBook Air 15" M3 avec GUID
|
||||
url = "https://www.backmarket.fr/fr-fr/p/macbook-air-153-2024-m3-avec-cpu-8-curs-et-gpu-10-curs-24go-ram-ssd-512go-azerty-francais/35bb170a-8d14-4649-9b7d-4429c493a68b"
|
||||
|
||||
print("=" * 80)
|
||||
print("TEST BACKMARKET - MACBOOK AIR 15\" M3")
|
||||
print("=" * 80)
|
||||
print(f"\nURL: {url}")
|
||||
|
||||
# Fetch avec Playwright (obligatoire pour Backmarket)
|
||||
print("\n[1/3] Récupération de la page avec Playwright...")
|
||||
result = fetch_playwright(url, headless=True, timeout_ms=60000)
|
||||
|
||||
if not result.success:
|
||||
print(f"❌ ÉCHEC du fetch: {result.error}")
|
||||
exit(1)
|
||||
|
||||
print(f"✓ Page récupérée: {len(result.html):,} caractères")
|
||||
print(f" Durée: {result.duration_ms}ms")
|
||||
|
||||
# Sauvegarder le HTML
|
||||
html_file = "scraped/backmarket_macbook_m3_pw.html"
|
||||
with open(html_file, "w", encoding="utf-8") as f:
|
||||
f.write(result.html)
|
||||
print(f"✓ HTML sauvegardé: {html_file}")
|
||||
|
||||
# Parser avec BackmarketStore
|
||||
print("\n[2/3] Parsing avec BackmarketStore...")
|
||||
store = BackmarketStore()
|
||||
snapshot = store.parse(result.html, url)
|
||||
|
||||
# Afficher les résultats
|
||||
print("\n[3/3] RÉSULTATS DU PARSING")
|
||||
print("-" * 80)
|
||||
print(f"Source: {snapshot.source}")
|
||||
print(f"URL: {snapshot.url}")
|
||||
print(f"Reference (SKU): {snapshot.reference}")
|
||||
print(f"Title: {snapshot.title}")
|
||||
print(f"Price: {snapshot.price} {snapshot.currency}")
|
||||
print(f"Stock: {snapshot.stock_status}")
|
||||
print(f"Images: {len(snapshot.images)} images")
|
||||
if snapshot.images:
|
||||
for i, img in enumerate(snapshot.images[:3]):
|
||||
print(f" [{i+1}] {img[:80]}...")
|
||||
|
||||
print(f"\nCategory: {snapshot.category or 'Non extraite'}")
|
||||
print(f"Specs: {len(snapshot.specs)} caractéristiques")
|
||||
if snapshot.specs:
|
||||
for key, value in list(snapshot.specs.items())[:7]:
|
||||
print(f" • {key}: {value}")
|
||||
|
||||
print(f"\nDebug status: {snapshot.debug.status}")
|
||||
print(f"Debug errors: {len(snapshot.debug.errors)}")
|
||||
for err in snapshot.debug.errors:
|
||||
print(f" ⚠️ {err}")
|
||||
|
||||
print(f"Debug notes: {len(snapshot.debug.notes)}")
|
||||
for note in snapshot.debug.notes:
|
||||
print(f" 📝 {note}")
|
||||
|
||||
print(f"\nIs complete: {'✓ OUI' if snapshot.is_complete() else '✗ NON'}")
|
||||
|
||||
# Export JSON
|
||||
json_file = "scraped/backmarket_macbook_m3_detail.json"
|
||||
json_data = snapshot.to_dict()
|
||||
with open(json_file, "w", encoding="utf-8") as f:
|
||||
json.dump(json_data, f, indent=2, ensure_ascii=False)
|
||||
|
||||
print(f"\n✓ JSON sauvegardé: {json_file}")
|
||||
|
||||
print("\n" + "=" * 80)
|
||||
if snapshot.is_complete():
|
||||
print("✅ TEST RÉUSSI - Parsing complet")
|
||||
else:
|
||||
print("⚠️ TEST PARTIEL - Données manquantes")
|
||||
print("=" * 80)
|
||||
Reference in New Issue
Block a user