I'm trying to grab the href value of an element using PHP, but I'm having some trouble. Here's a snippet of my code.
<?php
ini_set("log_errors", 1);
ini_set("error_log", "php-error.log");
$target_url = "http://foo.bar";
$request = $target_url;
$html = $this->scraper($request);
$dom = new DOMDocument();
$dom->loadHTML($html);
// Error point - $dom is empty
error_log("dom:");
error_log($dom);
$xpath = new DOMXPath($dom);
error_log("setting target url");
$target_url = $xpath->query("//*[@class='foo_bar']/href");
?>
Logging $html results in the standard, full HTML output of the page. A search shows that my xpath should work. However, when I try to log $dom after loadHTML, I get a blank result. I've been struggling for a few hours trying to work out why, but with no luck.
Does anyone have any ideas/anything I could try?
Edited to add console output:
[30-Sep-2015 13:51:59 America/New_York] dom:
[30-Sep-2015 13:51:59 America/New_York] setting target url