简体   繁体   中英

using php curl to extract data from a website with multiple submits

I have to extract data from a website via multiple submits and this has to be done automatically... the flow is as follows...

  1. Go to this page...http://www.licindia.in/premium_calculator.htm.
  2. Select something and then submit it. This will take me to a form
  3. Fill up the form there and submit it...
  4. get the html that is produced. and extract data.

I have used curl earlier to log into websites remotely but I cant seem to get this working anyway.

$url="http://www.licindia.in/premium_calculator.htm";
$postdata = "thepostdata"
$cookie = "cookie.txt" ;
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0");
curl_setopt($ch,CURLOPT_COOKIESESSION,false); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt ($ch, CURLOPT_REFERER, $referer);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch);
curl_close($ch);

Something like this i have tried...this is not the actual thing..but this is similar

I think your first issue is that the form on the page you linked is actually loaded from an iframe .

You will want to use that iframe 's url instead since cURL will not load the iframe srouce from the parent page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM