php - Extracting the value from webpage using simple html dom -
i have searched on net , found way extract data using simple html dom it's giving me following error:
warning: file_get_contents(http://www.flipkart.com/moto-g-2nd-gen/p/itme6g3wferghmv3): failed open stream: http request failed! http/1.1 500 server error in c:\users\abhishek\desktop\editor\request\simple_html_dom.php on line 75
fatal error: call member function find() on boolean in c:\users\abhishek\desktop\editor\request\main.php on line 9
my designed php code is:
<?php include('simple_html_dom.php'); $html = file_get_html('http://www.flipkart.com/moto-g-2nd-gen/p/itme6g3wferghmv3'); foreach($html->find('span.selling-price.omniture-field') $e) echo $e->outertext . '<br>'; ?>
i new in programming , don't have enough knowledge there mistake in program?
the server rejecting request based on user-agent, try using curl page html, i.e.
<?php $url="http://www.flipkart.com/moto-g-2nd-gen/p/itme6g3wferghmv3"; $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') $e) echo $e->outertext . '<br>';
output:
rs. 10,999
note:
i can confirm server rejecting request based on user-agent.
Comments
Post a Comment