代码示例:
$url = 'https://www.libaocai.com'; $html = file_get_contents($url); $dom = new DOMDocument(); @$dom->loadHTML($html); $xpath = new DOMXPath($dom); $hrefs = $xpath->evaluate("/html/body//a"); for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); echo $url.'<br />'; }
返回结果示例:
转载请注明:苏demo的别样人生 » php获取页面链接信息