我在网址http://www.flipkart.com/moto-g-2nd-gen/p/itme6g3wferghmv3上找到flipkart价格的初始脚本完美无缺,但当我找到网址http://www.flipkart.com/samsung-galaxy-core-2-sm-g355hzwdins/p/itmdy3h6qhgz2phv的价格时,脚本会出错:
致命错误:在布尔值中调用成员函数find() 第18行的C:\ Users \ Abhishek \ Desktop \ editor \ request \ main.php
这是我的代码:
<?php
$url="http://www.flipkart.com/samsung-galaxy-core-2-sm-g355hzwdins/p/itmdy3h6qhgz2phv";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_ENCODING, "");
$pagebody=curl_exec($ch);
curl_close ($ch);
include('simple_html_dom.php');
$html = str_get_html($pagebody);
foreach($html->find('.selling-price') as $e)
echo $e->outertext . '<br>';
?>