简体   繁体   中英

CURL isn't working as expected

I am trying to scrape a website after filling that form with my defined attributes and automating the submit action too. Then, i would scrape the data in the result page.

However, i haven't coded that part yet. But, when i compile it, the normal webpage http://www.indianrail.gov.in/pnr_Enq.html is being displayed (The url on which i want to submit the form and fetch the result page).

The submitted result page is not being displayed. I am taking this ruby script as reference https://github.com/alagu/pnrapi-ruby/blob/master/models/status.rb#L15

$ch = curl_init();
$timeout=5;
$name=$_REQUEST['name'];
$pass=$_REQUEST['pass'];
$rand_captcha = '11111';
$data = array('lccp_pnrno1' => '2257870493', 'submitpnr' => 'Get Status', 'lccp_cap_val' => $rand_captcha, 'lccp_capinp_val' => $rand_captcha);
//$data=http_build_query($data);
curl_setopt($ch,CURLOPT_URL,"http://www.indianrail.gov.in/pnr_Enq.html"); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$data = curl_exec($ch);
echo $data;
curl_close($ch);

$curl_connection应该是$ch

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