Using DOM, you can easily grab links from any page. The code example is as follows:
Copy the code The code is as follows:
$html = file_get_contents('http://www.example.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.'
';
}
http://www.bkjia.com/PHPjc/621705.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/621705.htmlTechArticleUsing DOM, you can easily grab links from any page. The code example is as follows: Copy the code The code is as follows: $ html = file_get_contents('http://www.example.com'); $dom = new DOMDocum...