0
주어진 사이트에서 모든 하이퍼 링크를 얻고 싶습니다. 그래서이 코드를 작성합니다. 하지만 제대로 작동하지 않습니다. 지정된 URL의 모든 하이퍼 링크 만 보여줍니다. 하지만 주어진 사이트의 모든 하이퍼 링크를 얻고 싶습니다. 예 주어진 URL의 전체 페이지 href를 얻으십시오
<?php
function getAlllinks($site){
$link = file_get_contents($site);
$dom = new DOMDocument;
@$dom->loadHTML($link);
$links = $dom->getElementsByTagName('a');
foreach ($links as $link){
$url = $link->getAttribute('href');
if($url[0]!="#" && $url[0]!=" "){
echo $url. '<br>';
getAlllinks($url);
}
}
}getAlllinks("http://www.example.com");
?>
여기
<html>
<body>
<a href="index.php">Homepage</a>
<a href="contact.php">Contact</a>
</body>
</html>
index.php를 먼저하고 contact.php 또는 접점의 모든 링크를 표시한다 다음 하이퍼 링크와의 index.php contact.php &을 보여줄 것이다. PHP는 http://www.example.com/contact.php
검색 – SML