什麼是正確的語法使用xpath獲取所有div的內容與某個類?我似乎正在獲得divs,但我不知道如何獲得他們的innerHTML。php xpath獲取div的內容與類
$url = "http://www.vanityfair.com/politics/2012/10/michael-lewis-profile-barack-obama";
$ctx = stream_context_create(array('http'=> array('timeout' => 10)));
libxml_use_internal_errors(TRUE);
$num = 0;
if($html = @file_get_contents($url,false,$ctx)){
$doc = DOMDocument::loadHTML($html);
$xpath = new DOMXPath($doc);
foreach($xpath->query('//div[@class="page-display"]') as $div){
$num++;
echo "$num. ";
//????
echo "<br/>";
}
echo "<br/>FINISHED";
}else{
echo "FAIL";
}
你試過'$ div-> nodeValue'或'$ div-> textContent' – Musa
確實這樣做了,沒有運氣 – David