I'm trying to count div with class classtosearch
in a result from curl.
PIece of code:
<div class="classtosearch other_class">Content</div>
<div class="classtosearch other_class_1">Content</div>
<div class="classto_NOT_search other_class">Content</div>
This is my code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL,"http://www.example.org");
$buf2 = curl_exec($ch);
curl_close ($ch);
$doc = new DOMDocument();
$doc->loadHTML($buf2);
$xpath = new DOMXPath($doc);
$divs= $xpath->query("//div[@class='classtosearch']");
echo "Found " . $divs->length . " divs";
I get always 0 as result and a lot of warning:
Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity
Warning: DOMDocument::loadHTML(): htmlParseEntityRef: no name in Entity
Warning: DOMDocument::loadHTML(): Tag footer invalid in Entity
But My test page has 2 divs with class classtosearch