您的位置:首页 > 编程语言 > PHP开发

php查找页面上的所有链接

2016-06-22 21:04 405 查看
使用DOM,你可以轻松从任何页面上抓取链接,代码示例如下:
$html = file_get_contents('http://www.php100.com');

$dom = new DOMDocument();
@$dom->loadHTML($html);

// grab all the on the page
$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 />';
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: