Actualiser api.php
This commit is contained in:
@@ -690,28 +690,45 @@ switch ($action) {
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
break;
|
||||
|
||||
case 'test_covercentury':
|
||||
case 'test_covercentury':
|
||||
$title = $_GET['title'] ?? 'Matrix';
|
||||
$year = $_GET['year'] ?? '';
|
||||
|
||||
// URLs possibles à tester
|
||||
$urls = [
|
||||
"https://www.covercentury.com/index.php?p=recherche&recherche=" . urlencode($title),
|
||||
"https://www.covercentury.com/?s=" . urlencode($title),
|
||||
"https://www.covercentury.com/search/" . urlencode($title),
|
||||
"https://www.covercentury.com/index.php?recherche=" . urlencode($title),
|
||||
];
|
||||
|
||||
$results = [];
|
||||
foreach ($urls as $url) {
|
||||
$url = "https://www.covercentury.com/index.php?p=recherche&recherche=" . urlencode($title);
|
||||
$html = httpGet($url, 8);
|
||||
$results[] = [
|
||||
'url' => $url,
|
||||
'length' => $html ? strlen($html) : 0,
|
||||
'snippet' => $html ? substr(strip_tags($html), 0, 200) : 'ERREUR'
|
||||
];
|
||||
if (!$html) { echo json_encode(['error' => 'ERREUR réseau']); break; }
|
||||
|
||||
$dom = new DOMDocument();
|
||||
@$dom->loadHTML($html);
|
||||
$xpath = new DOMXPath($dom);
|
||||
|
||||
// Tous les liens
|
||||
$allLinks = $xpath->query('//a');
|
||||
$links = [];
|
||||
foreach ($allLinks as $a) {
|
||||
$href = $a->getAttribute('href');
|
||||
$text = trim($a->textContent);
|
||||
if (!empty($href) && !empty($text) && $href !== '#') {
|
||||
$links[] = ['text' => substr($text, 0, 80), 'href' => $href];
|
||||
}
|
||||
echo json_encode($results, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
if (count($links) >= 20) break;
|
||||
}
|
||||
|
||||
// Toutes les images
|
||||
$allImgs = $xpath->query('//img');
|
||||
$imgs = [];
|
||||
foreach ($allImgs as $img) {
|
||||
$imgs[] = [
|
||||
'src' => $img->getAttribute('src'),
|
||||
'alt' => $img->getAttribute('alt'),
|
||||
'class' => $img->getAttribute('class'),
|
||||
];
|
||||
if (count($imgs) >= 20) break;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'url' => $url,
|
||||
'links' => $links,
|
||||
'imgs' => $imgs
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
break;
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user