第一步先获取strIdentity
$url = "http://www.shenzhenair.com/common/flightSearch.do"; 
$ch = curl_init();  
$timeout = 1;  
$mudedi1 = urlencode("SZX;S-深圳");
$mudedi2 = urlencode("PEK;B-北京");
$data = "productId=00000000001&PRODUCT_ID=000000000448&orgDate10=2011-04-10&orgDate20=&allVar=&operate=goLoadingPage&platID=plat_1&originalPage=wshdpGN&flightConditionEntity.changedOrgCity=&flightConditionEntity.hbType=GN&flightConditionEntity.orgCity1[0]=".$mudedi1."&orgCity10=".$mudedi1."&flightConditionEntity.dstCity0=".$mudedi2."&flightConditionEntity.orgDate1[0]=2011-04-10&flightConditionEntity.orgDate2[0]=&flightConditionEntity.hcType=DC";
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($ch, CURLOPT_REFERER, "http://www.shenzhenair.com/common/flightSearch.do?operate=goLoadingPage&originalPage=index&lan=zh");  
$cookie_jar = "D:\Apache2.2\htdocs\shenzhenair\cookie.txt";
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);  
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/x-www-form-urlencoded;charset=GBK")); 
$contents = curl_exec($ch);
curl_close($ch); 
$contents = str_replace("onLoad=\"load();\"","",$contents);//把函数替换掉,不让它自动跳转
$temp1 = split("name=\"strIdentity\" value=\"",$contents);
$temp2 = split("\"",$temp1[1]);
$strIdentity = $temp2[0];
//这里可以获取到$strIdentity这个值第二步模拟查询
$ch = curl_init();
$timeout = 1; 
$mudedi1 = "SZX;S-深圳";
$mudedi2 = "PEK;B-北京";
$mudedi1 = urlencode("SZX;S-深圳");
$mudedi2 = urlencode("PEK;B-北京");
$data = "operate=flightSearch&originalPage=index&flightConditionEntity.hcType=DC&flightConditionEntity.hbType=GN&flightConditionEntity.productId=&flightConditionEntity.orgDate=&flightConditionEntity.orgCity2=".$mudedi1."&flightConditionEntity.orgCity3=".$mudedi1."&flightConditionEntity.orgCity=&orgCity10=".$mudedi1."&orgDate10=2011-04-10&orgDate20=&transfer=0&flightConditionEntity.dstCity=&flightConditionEntity.dstCity0=".$mudedi2."&flightConditionEntity.dstCity1=&flightConditionEntity.dstCity2=&flightConditionEntity.dstCity3=&flightConditionEntity.isExchangeFreeTicket=false&isChangedDay=null&strIdentity=".$strIdentity;
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($ch, CURLOPT_REFERER, "http://www.shenzhenair.com/common/flightSearch.do?operate=goLoadingPage&originalPage=index&lan=zh");  
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_COOKIE, $cookie_jar);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/x-www-form-urlencoded;charset=GBK"));  
//curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
$contents = curl_exec($ch);
echo $contents.'<br>';
curl_close($ch); 输出还总是提示查询已过期,这个问题头疼了很久,有高手快来看看,两帖一起给分,不甚感激。

解决方案 »

  1.   

    验证通过$url = "http://www.shenzhenair.com/common/flightSearch.do"; 
    $referer = 'http://www.shenzhenair.com/common/flightSearch.do?operate=goLoadingPage&originalPage=index&lan=zh';
    $cookie_jar = dirname(__FILE__)."/cookie.txt"; 
    $timeout = 1;  
    $mudedi1 = urlencode("SZX;S-深圳");
    $mudedi2 = urlencode("PEK;B-北京");
    $data = "productId=00000000001&PRODUCT_ID=000000000448&orgDate10=2011-04-10&orgDate20=&allVar=&operate=goLoadingPage&platID=plat_1&originalPage=wshdpGN&flightConditionEntity.changedOrgCity=&flightConditionEntity.hbType=GN&flightConditionEntity.orgCity1[0]=".$mudedi1."&orgCity10=".$mudedi1."&flightConditionEntity.dstCity0=".$mudedi2."&flightConditionEntity.orgDate1[0]=2011-04-10&flightConditionEntity.orgDate2[0]=&flightConditionEntity.hcType=DC";
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_URL, $url);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
    curl_setopt($ch, CURLOPT_REFERER, $referer);  
    curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);  
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
    $contents = curl_exec($ch);
    curl_close($ch); if(preg_match('/<input\s+type="hidden"\s*name="strIdentity"\s+value="(.*?)"\/>/i',$contents,$arr)){
      $strIdentity = $arr[1];
    }
    $ch = curl_init();
    $timeout = 1; 
    $mudedi1 = "SZX;S-深圳";
    $mudedi2 = "PEK;B-北京";
    $mudedi1 = urlencode("SZX;S-深圳");
    $mudedi2 = urlencode("PEK;B-北京");
    $data = "operate=flightSearch&originalPage=index&flightConditionEntity.hcType=DC&flightConditionEntity.hbType=GN&flightConditionEntity.productId=&flightConditionEntity.orgDate=&flightConditionEntity.orgCity2=".$mudedi1."&flightConditionEntity.orgCity3=".$mudedi1."&flightConditionEntity.orgCity=&orgCity10=".$mudedi1."&orgDate10=2011-04-10&orgDate20=&transfer=0&flightConditionEntity.dstCity=&flightConditionEntity.dstCity0=".$mudedi2."&flightConditionEntity.dstCity1=&flightConditionEntity.dstCity2=&flightConditionEntity.dstCity3=&flightConditionEntity.isExchangeFreeTicket=false&isChangedDay=null&strIdentity=".$strIdentity;
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_URL, $url);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
    curl_setopt($ch, CURLOPT_REFERER, $referer);  
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    $contents = curl_exec($ch);
    echo $contents.'<br>';
    curl_close($ch);  
      

  2.   

    curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    这两个可以去掉,照样执行
      

  3.   

    太感谢了,你去
    http://topic.csdn.net/u/20110314/16/4964468a-478b-4a58-8f3a-74fa7aad02e4.html?seed=697716775&r=72164432#r_72164432
    这个帖子也回复下吧,给你分。