Jump to content

Problem with CURL for a page using AJAX


rahulag38

Recommended Posts

Hello,

  First of all ,I have been a regular reader of the forum and it has increased my knowledge in the PHP a lot.  :D

Till now i had just been a guest user and used to go through the queries and tips posted here.

 

Today , for the first time i am posting on the forum

 

Coming to a problem:

I have to design a function for a client from travel domain. Where he wants the script/function to go and extract data from an airline website on the available fare for a specific date and destination. The problem is that only a part of fare(Base fare) is visible on the site and you have to select one of the given flight option(s) (after selecting the option through AJAX the full fare is displayed on the same page on the left hand site) to get the complete fare including fare and surcharges.

 

Now i want my function/script to extract the full fare for all the available flight options. I have written the below piece of code. But its not efffective as it gets only the base fare part of the result page and not the complete fare..  :-[

 

The airline booking url is : http://book.spicejet.com/skylights/cgi-bin/skylights.cgi

 

My code:

 

//---- Spicejet start

// ENGINE URL http://book.spicejet.com/skylights/cgi-bin/skylights.cgi?page=homecomp

 

//Taking some sample search data - just to test the script

$event="search" ;

$module="SB" ;

$page="SEARCH" ;

$mode="empty" ;

$travel="1" ;    // ONE WAY OR 2 WAY

$from1="HYD" ;

$to1="DEL" ;

$departDay1="13" ;

$departDay2="";

$departMonth1="201010" ;

$ADULT="1" ;

$CHILD="0" ;

$INFANT="0" ;

$toCity1="DEL" ;

$numberMarkets="1" ;

 

// the page needs data in POST form

$curlPost = 'event='  . urlencode($event) . '&module=' . urlencode($module) .'&page=' . urlencode($page) .'&mode=' . urlencode($mode) .'&travel=' . urlencode($travel) .'&from1=' . urlencode($from1) .'&to1=' . urlencode($to1) .'&departDay1=' . urlencode($departDay1) .'&departMonth1=' . urlencode($departMonth1) .'&ADULT=' . urlencode($ADULT) .'&CHILD=' . urlencode($CHILD) .'&INFANT=' . urlencode($INFANT) .'&toCity1=' . urlencode($toCity1) .'&numberMarkets=' . urlencode($numberMarkets).'&submitSearch=submitSearch';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://book.spicejet.com/skylights/cgi-bin/skylights.cgi');

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322)");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);

$data = curl_exec($ch);

curl_close($ch);

 

echo($data); 

 

 

 

Also one more query Is there something like beautiful soup (As in Python) to parse the data. I want to extract the flight timing and total price from the page and insert into a database.

 

Thanxs in advance

Link to comment
https://forums.phpfreaks.com/topic/214423-problem-with-curl-for-a-page-using-ajax/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.