我需要获取我访问过的特定节点的子节点(带有 class = title 的 li 节点)
请帮帮我,我该怎么做?
<?php
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "SomeUcam v0.1 Bot", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init( "http://example.com/?page=1" );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$newDom = new domDocument;
$newDom->loadHTML($content);
$finder = new DomXPath($newDom);
$classname="title";
$nodes = $finder->query("//*[contains(@class, '$classname')]");
$nodesNo = $nodes->length;
echo $nodesNo;
?>