This class is from a video tutorial I did on youtube. It is very simple and should be built upon. I will keep this version the same as the video.
##Basic Example
// Create an instance of XPATH
$path = new XPATH("http://example.com");
// An example query. This will grab all the link href attributes from a page
$links = $path->query("//a/@href");
// loop through and output node values
if($links->length > 0){
foreach($links as $link) {
echo $link->nodeValue . "<br>";
}
}
###Youtube videos on Scraping Websites with Xpath
- Scraping Websites with PHP using DOMDocument and DOMXpath
- Scraping Websites with PHP using DOMXpath and DOMDocument Part 2: Building an XPath Class
- Scraping Websites with PHP using DOMXpath and DOMDocument Part 3: Recursive Scraping
###More useful Links
I dont usually link to w3fools but they have a nice Xpath syntax reference, even MDN links to it.
Hope you find this useful.
-Nate Wiley