Rumah >pembangunan bahagian belakang >tutorial php > php应用xpath抽取网页超链接
php使用xpath抽取网页超链接
<?php $html=file_get_contents('http://www.163.com/'); $doc=new DomDocument(); $doc->loadHTML($html); $xpath=new DOMXpath($doc); foreach($xpath->query('//a/@href') as $node){ $link = $node->nodeValue; echo $link . "\n"; } ?>