获取网站里面a的链接,想到用个php函数实现,如何操作?
<?php function sj($url){ $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'); } } $url='http://www.henenseo.com/'; sj($url); ?>
评论前必须登录!
注册