I'm trying to grab a specific bit of raw text from a web site. Using this site and other sources, I learned how to grab specific images using simpleXML and xpath.
However the same approach doesn't appear to be working for grabbing raw text. Here's what's NOT working right now.
// first I set the xpath of the div that contains the text I want
$xpath = '//*[@id="storyCommentCountNumber"]';
// then I create a new DOM Document
$html = new DOMDocument();
// then I fetch the file and parse it (@ suppresses warnings).
@$html->loadHTMLFile($url);
// then convert DOM to SimpleXML
$xml = simplexml_import_dom($html);
// run an XPath query on the div I want using the previously set xpath
$commcount = $xml->xpath($xpath);
print_r($commcount);
Now when I'm grabbing an image, that commcount object would return an array that contains the images source in it somewhere.
In this case, I want that object to return the raw text contained in the "storyCommentCountNumber" div. But that text doesn't appear to be contained in the object, just the name of the Div.
What am I doing wrong? I can kind of see that this approach is only for grabbing HTML elements and the bits inside of them, not raw text. How do I get the text inside that div?
Thanks!