本文共 1153 字,大约阅读时间需要 3 分钟。
$html = curl($url);libxml_use_internal_errors(true);$dom = new DOMDocument();$dom->loadHTML($html);
loadHTMLFile('http://netkiller.github.io/'); $xpath = new DOMXPath($doc);$title = $xpath->evaluate('string(/html/head/title)'); echo "Document title is: " . $title . "\n";?>
referer = $url; return $response; }$url = "http://netkiller.github.io/journal/index.html";$html = curl($url);libxml_use_internal_errors(true);$dom = new DOMDocument();$dom->loadHTML($html);$xpath = new DOMXPath($dom);$xml = $xpath->query('//div[@class="section"]');foreach ($xml as $result_object){ //echo $result_object->childNodes->item(0)->nodeValue; print_r($result_object);}
下面的例子是从某个网站扣取一个HTML块的例子
$url = "http://netkiller.github.io/journal/index.html";$html = curl($url);libxml_use_internal_errors(true);$dom = new DOMDocument();$dom->loadHTML($html);$xpath = new DOMXPath($dom);$xml = $xpath->query('//div[@class="section"]');$xhtml = $dom->saveHTML($xml->item(0));print_r($xhtml);
原文出处:Netkiller 系列 手札
本文作者:陈景峯 转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。