What is the right syntax to use xpath to get the contents of all divs with a certain class? i seem to be getting the divs but i don't know how to get their innerHTML.
        $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";
    }
                There is no HTML in the class="page-display" divs - so you're not going to get anything at all.
Do you mean the get class="parbase cn_text"?
    foreach($xpath->query('//div[@class="parbase cn_text"]') as $div){
        $num++;
        echo "$num. ";
        //????
        echo $div->textContent;
        echo "<br/>";
    }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With