使用DOM,你可以轻松从任何页面上抓取链接,代码示例如下:
$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.\'<br />\';
}
本文地址:https://www.stayed.cn/item/16088
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我