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