Hello I write following code to extract name and price from table with XPATH and curl.
<?php
include_once ("xpath.php");
header('Content-type: text/html; charset=UTF-8');
$ch = curl_init ("http://emalls.ir/%D9%84%DB%8C%D8%B3%D8%AA-%D9%82%DB%8C%D9%85%D8%AA~Category~39~Search~Nokia");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//$page = curl_exec($ch);
$page = utf8_decode(curl_exec($ch));
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($page);
libxml_clear_errors();
$xpath = new DOMXpath($dom);
$data = array();
// get all table rows and rows which are not headers
$produstname = $xpath->query('//table/tbody/tr/td/a/text()');
$produstprice = $xpath->query('//table/tbody/tr/td[8]/text()');
$data = array();
for ($x=0; $x<=1; $x++){
$data[$x]['title'] = $produstname->item($x)->nodeValue;
$data[$x]['price'] = $produstprice->item($x)->nodeValue;
}
?>
These following two XPATH working on chrome to get name and price .
name: $x("//table/tbody/tr/td/a/text()")
price: $x("//table/tbody/tr/td[5]/text()")
but when use in following code give this error
: Trying to get property of non-object in