1

I am trying to find all line items with a class of "menu_item" and it's not turning anything up. The page most certainly has 'content ' scattered throughout, so that's not the problem. Thanks for any help you can offer!

$url = "http://www.examplesite.com";
$doc = new DOMDocument;

$html = file_get_contents($url);
$doc->loadHTML($html);
$xPath = new DOMXPath($doc);

$results = $xPath->query('//li[@class="menu_item"]');
print_r($results);

The printing only returns this: 'DOMNodeList Object ( )'

1 Answer 1

1

That is correct behavior since $xpath->query method returns an object of type DOMNodeList. Try iterating $results object like this:

if ($results) {
   for ($i=0; $i < $results->length; $i++) {
       $node = $results->item($i);
       var_dump($node);
   }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Provide a small sample of loaded HTML in your question then I can investigate further.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.