Here is my code:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$url = "http://www.sportsdirect.com/adidas-goletto-mens-astro-turf-trainers-263244?colcode=26324408";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($curl, CURLOPT_VERBOSE, true);
$str = curl_exec($curl);
curl_close($curl);
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTMLFile($str);
$xpath = new DOMXpath($doc);
$name = $xpath->query('//span[@id="ProductName"]')->item(0)->nodeValue;
echo $name;
?>
I am trying to parse the text placed in element <span id="ProductName">TEXT here</span> but i receive error:
Notice: Trying to get property of non-object in /home/sportsdi/public_html/test.php on line 28
Can you please tell me where is my mistake, i am stuck on this for hours ? How can i get the text in this element ?
Thanks in advance!
var_dupm($xpath)shows :-object(DOMXPath)#2 (1) { ["document"]=> string(22) "(object value omitted)" }means no data retrieve.