冰豆网

分享网络精彩
bingdou.com.cn

php提取页面中所有的超链接地址

时间:2020-02-20加入收藏

<?php
$html = file_get_contents('http://www.www.tseox.com/sitemap.html');
 
$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 />';
}
?>

本案例用于获取网站sitemap里面的所有连接提交到站长后台。如果获取页面的链接需要拼接一下变量加上网址!

打 赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

TGA: 技巧

分享到:


官方微信二维码冰豆网官方微信公众号