diff --git a/api.php b/api.php index af66980..7a71f24 100644 --- a/api.php +++ b/api.php @@ -116,47 +116,60 @@ function emptyPhysicalResult() { ]; } -// ── SCRAPPING FNAC (CORRIGÉ) ── +// ── SCRAPPING FNAC (CORRIGÉ POUR PARSER LA PAGE DE RÉSULTATS) ── function fetchFromFnac($ean) { $empty = emptyPhysicalResult(); $url = "https://www.fnac.com/SearchResult/ResultList.aspx?Search=" . urlencode($ean); - - $ch = curl_init($url); - curl_setopt_array($ch, [ - CURLOPT_RETURNTRANSFER => true, - CURLOPT_TIMEOUT => 10, - CURLOPT_SSL_VERIFYPEER => false, - CURLOPT_FOLLOWLOCATION => true, // Important pour suivre la redirection vers la page produit - CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0', - ]); - $html = curl_exec($ch); - $finalUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); // Récupère l'URL après redirection - curl_close($ch); - + $html = httpGet($url, 15); if (!$html) return $empty; - // ✅ CORRECTION : On vérifie si on a bien été redirigé vers une page produit - // Si l'URL finale contient encore "SearchResult", c'est qu'on est sur la page de recherche - // (avec les bannières sponsorisées type "Project Hail Mary"). On ignore pour éviter les pubs. - if (strpos($finalUrl, 'SearchResult/ResultList.aspx') === false && strpos($finalUrl, 'SearchResult') === false) { - - // On est sur la page produit ! On récupère le titre via og:title (infaillible) - if (preg_match('/]*property="og:title"[^>]*content="([^"]+)"/i', $html, $m)) { - $title = html_entity_decode(trim($m[1]), ENT_QUOTES | ENT_HTML5, 'UTF-8'); - // Nettoyage du titre FNAC qui peut contenir " | Fnac" à la fin - $title = preg_replace('/\s*\|\s*Fnac.*$/i', '', $title); - $empty['title'] = trim($title); - } elseif (preg_match('/