Vous pouvez extraire tous les liens d'une page Web, avec PHP et Curl.
<?php
$url_cible = $_GET["url"];
if (empty($url_cible)) {$url_cible = "https://www.google.com";}
echo "<div><b>URL cible</b> : " . $url_cible . "</div>";
echo "<div><b>Liste des liens relatifs et absolues</b> :</div>";
$userAgent = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)';
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$url_cible);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html= curl_exec($ch);
if (!$html) {
echo "<br />cURL erreur numéro:" .curl_errno($ch);
echo "<br />cURL erreur:" . curl_error($ch);
exit;
}
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$liens = $xpath->evaluate("/html/body//a");
for ($i = 0; $i < $liens->length; $i++) {
$lien = $liens->item($i);
$url = $lien->getAttribute('href');
echo "$url<br>";
}
?>
Référez-vous à cette autre question pour obtenir d'avantages de solutions pour parser et extraire un contenu spécifique, tel que les liens d'une page Web, avec PHP.