Actualiser api.php
This commit is contained in:
@@ -692,43 +692,39 @@ switch ($action) {
|
||||
|
||||
case 'test_covercentury':
|
||||
$title = $_GET['title'] ?? 'Matrix';
|
||||
$url = "https://www.covercentury.com/index.php?p=recherche&recherche=" . urlencode($title);
|
||||
$html = httpGet($url, 8);
|
||||
if (!$html) { echo json_encode(['error' => 'ERREUR réseau']); break; }
|
||||
$urls = [
|
||||
"https://www.covercentury.com/index.php?p=dvdcovers&recherche=" . urlencode($title),
|
||||
"https://www.covercentury.com/index.php?p=blu-raycovers&recherche=" . urlencode($title),
|
||||
"https://www.covercentury.com/index.php?p=dvdcovers&q=" . urlencode($title),
|
||||
"https://www.covercentury.com/index.php?p=dvdcovers&s=" . urlencode($title),
|
||||
];
|
||||
|
||||
$dom = new DOMDocument();
|
||||
@$dom->loadHTML($html);
|
||||
$xpath = new DOMXPath($dom);
|
||||
$results = [];
|
||||
foreach ($urls as $url) {
|
||||
$html = httpGet($url, 8);
|
||||
if (!$html) { $results[] = ['url' => $url, 'length' => 0, 'snippet' => 'ERREUR']; continue; }
|
||||
|
||||
// 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];
|
||||
$dom = new DOMDocument();
|
||||
@$dom->loadHTML($html);
|
||||
$xpath = new DOMXPath($dom);
|
||||
|
||||
$allImgs = $xpath->query('//img');
|
||||
$imgs = [];
|
||||
foreach ($allImgs as $img) {
|
||||
$src = $img->getAttribute('src');
|
||||
if (strpos($src, 'logo') === false && strpos($src, 'assets') === false) {
|
||||
$imgs[] = ['src' => $src, 'alt' => $img->getAttribute('alt')];
|
||||
}
|
||||
if (count($imgs) >= 10) break;
|
||||
}
|
||||
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'),
|
||||
$results[] = [
|
||||
'url' => $url,
|
||||
'length' => strlen($html),
|
||||
'imgs' => $imgs
|
||||
];
|
||||
if (count($imgs) >= 20) break;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'url' => $url,
|
||||
'links' => $links,
|
||||
'imgs' => $imgs
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
echo json_encode($results, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
break;
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user