我正在尝试使用PHP和cURL发布到网站,并获取搜索结果作为概念的刮擦证明的一部分。但是响应与通过直接访问网站获得的响应不同。我已经使用FireBug捕获了所有帖子参数和标题,并使用cURL发送了所有这些参数和参数,但响应仍然不一样。有人可以帮忙搞清楚我能做错什么吗?
我尝试访问的网站是:http://book.goindigo.in/skylights/cgi-bin/skylights.cgi
在该网站中,我正在进行单向搜索,这将返回一堆航班(例如,9月25日的孟买 - 德里)。我并不担心这个结果。显示航班后,如果选择了特定航班,则会在价格摘要部分下方的左侧显示票价分手。为了获得这个价格摘要,他们正在激活ajax调用,这是我想用PHP和cURL模拟的。
当通过网站访问时,ajax调用返回一堆javascript变量作为响应。但是同一个调用返回页面的完整html而不是通过cURL访问时预期的javascript变量。
任何帮助都将不胜感激。
由于
$url='https://book.goindigo.in/skylights/cgi-bin/skylights.cgi';
$header = array("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language: en-us,en;q=0.5", "Connection: keep-alive", "Cache-Control: no-cache", "Accept-Encoding: gzip,deflate", "Content-Length: 342", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Cookie: __utma=1.649498667.1346160326.1346395277.1346415046.4; __utmz=1.1346160326.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmb=1.11.10.1346415046; __utmc=1", "Host: book.goindigo.in", "Pragma: no-cache", "Referer: https://book.goindigo.in/skylights/cgi-bin/skylights.cgi");
$user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:15.0) Gecko/20100101 Firefox/15.0";
$referrer = 'https://book.goindigo.in/skylights/cgi-bin/skylights.cgi' ;
$post_params="page=INCLUSIVE_PRICING&module=SB&sid=&adults=1&children=0&language=EN&infants=0&numberMarkets=1&market1Data=201209036E%20146BLRDEL%20ININERE0BLRDEL201209031345201209031630Regular%20Fare%20ADULT%20ADT%2001&market2Data=&flt1_cnx1_date=&flt1_cnx2_date=&flt1_paxType1_fare=440000&flt1_paxType2_fare=&itin_type=Domestic";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
#curl_setopt($ch, CURLOPT_PROXY, $proxy);
#curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$result = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
echo $result;
答案 0 :(得分:0)
你错过了:
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
这是我在shell中所做的:
curl -d "page=INCLUSIVE_PRICING&module=SB&sid=&adults=1&children=0&language=EN&infants=0&numberMarkets=2&market1Data=201209116E 176BOMDEL ININERE0BOMDEL201209111325201209111530Regular Fare ADULT ADT 01&market2Data=201209116E 175DELBOM ININNRN0BOMDEL201209111345201209111555RoundTrip Fare ADULT ADT 01&flt1_cnx1_date=&flt1_cnx2_date=&flt2_cnx1_date=&flt2_cnx2_date=&flt1_paxType1_fare=443000&flt1_paxType2_fare=&flt2_paxType1_fare=402000&flt2_paxType2_fare=&itin_type=Domestic" http://book.goindigo.in/skylights/cgi-bin/skylights.cgi
输出结果为:
<!--
//////////////////////////////////////////////////////////////////////////////
// Copyright(c) 2000 - 2006 Navitaire Inc. All rights reserved. //
// //
// This source code is protected by copyright law and international //
// treaties. Unauthorized reproduction, distribution or alteration //
// of this source code, or any portion of it, may result in severe //
// civil and criminal penalties and will be prosecuted to the maximum //
// extent possible under the law. //
// //
// Skylights 9.4b-6E www.navitaire.com //
//////////////////////////////////////////////////////////////////////////////
-->
numRoutes=2;
r1destination=DEL;
r1origin=BOM;
r1fareLabel=Regular Fare ;
r1Pax1Type=ADT;
r1Pax1DiscountBase= Rs 4,430.00 ;
r1Pax1TotalFareCost= Rs 8,426.00 ;
r1Pax1Tax1Amount= Rs 233.00 INR;
r1Pax1Tax1SummedAmount=233.00;
r1Pax1Tax1Desciption=Passenger Service Fee;
r1Pax1Tax2Amount= Rs 2,800.00 INR;
r1Pax1Tax2SummedAmount=2800.00;
r1Pax1Tax2Desciption=Fuel Surcharge;
r1Pax1Tax3Amount= Rs 50.00 INR;
r1Pax1Tax3SummedAmount=50.00;
r1Pax1Tax3Desciption=Transaction Charge;
r1Pax1Tax4Amount= Rs 360.00 INR;
r1Pax1Tax4SummedAmount=360.00;
r1Pax1Tax4Desciption=Service Tax;
r1Pax1Tax6Amount= Rs 553.00 INR;
r1Pax1Tax6SummedAmount=553.00;
r1Pax1Tax6Desciption=User Development Fee;
r1Pax1TotalTaxAmount= Rs 3,996.00 ;
r1Pax1SummedFareAmount=4430.00;
r1Pax1SummedFareAmount=4430.00;
r1Pax1SummedTaxAmount= Rs 3,996.00 ;
r1InfDescription=;
r1InfDiscountBase= Rs 0.00 ;
r1InfSSRCode=;
r1InfTotalFareCost= Rs 0.00 ;
r1TotalInfTaxAmount= Rs 0.00 ;
r1RouteTotalTax= Rs 3,996.00 ;
r1RouteTotalAmount= Rs 8,426.00 ;
r1InfSummedFareAmount= Rs 0.00 ;
r1InfSummedTaxAmount= Rs 0.00;
r1SummedTaxAmount= Rs 3,996.00 ;
r1SummedAmount= Rs 8,426.00 ;
r2destination=BOM;
r2origin=DEL;
r2fareLabel=RoundTrip Fare ;
r2Pax1Type=ADT;
r2Pax1DiscountBase= Rs 4,020.00 ;
r2Pax1TotalFareCost= Rs 8,101.00 ;
r2Pax1Tax1Amount= Rs 146.00 INR;
r2Pax1Tax1SummedAmount=146.00;
r2Pax1Tax1Desciption=Passenger Service Fee;
r2Pax1Tax2Amount= Rs 2,800.00 INR;
r2Pax1Tax2SummedAmount=2800.00;
r2Pax1Tax2Desciption=Fuel Surcharge;
r2Pax1Tax3Amount= Rs 50.00 INR;
r2Pax1Tax3SummedAmount=50.00;
r2Pax1Tax3Desciption=Transaction Charge;
r2Pax1Tax4Amount= Rs 340.00 INR;
r2Pax1Tax4SummedAmount=340.00;
r2Pax1Tax4Desciption=Service Tax;
r2Pax1Tax6Amount= Rs 745.00 INR;
r2Pax1Tax6SummedAmount=745.00;
r2Pax1Tax6Desciption=User Development Fee;
r2Pax1TotalTaxAmount= Rs 4,081.00 ;
r2Pax1SummedFareAmount=4020.00;
r2Pax1SummedFareAmount=4020.00;
r2Pax1SummedTaxAmount= Rs 4,081.00 ;
r2InfDescription=;
r2InfDiscountBase= Rs 0.00 ;
r2InfSSRCode=;
r2InfTotalFareCost= Rs 0.00 ;
r2TotalInfTaxAmount= Rs 0.00 ;
r2RouteTotalTax= Rs 4,081.00 ;
r2RouteTotalAmount= Rs 8,101.00 ;
r2InfSummedFareAmount= Rs 0.00 ;
r2InfSummedTaxAmount= Rs 0.00;
r2SummedTaxAmount= Rs 4,081.00 ;
r2SummedAmount= Rs 8,101.00 ;
TransactionFeeAmount=0.00;
TotalPackageAmount=Rs 16,527.00 ;
PrefixType=Rs ;