php-ccurl试图检索页面,但无法工作


php curl trying to retrieve page but not working

我正在尝试从该页面检索表单。我设置了cookie,还发送了表单数据,但我得到的只是无效页面。

$ckfile = tempnam ("/tmp", "CURLCOOKIE");

$ch = curl_init ("http://services.www.gov.qa/TV/process/TV/TV_TrafficViolation?lang=en&notloggedin=true");
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec ($ch);

$ch = curl_init ("http://services.www.gov.qa/TV/continue/TV/TV_TrafficViolation/2/CPN");
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
$data = array(
    'sopEngineTabRef' => '1376927282615',
    'act' => 'byCarPlateNo',
    'txiVehicleNumber' => '',
    'mnuVehicleType' => 'PRV',
    'vehicleNumberNType' => '12332/PRV',
    'searchCriteria' => '1',
    'searchCriteria' => 'qatariUser1',
    'vehicleNumberAndType' => '12332/PRV',
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
echo $output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

在我看来,一个问题是您返回的页面包含大量jQuery/js/ajax内容,您必须解析和解释这些内容——curl基本上只是显示html。此外,它还退货,如:

<script type="text/javascript" src="/TV/hukoomi/scripts/hukoomi_combined_js.js"></script>

脚本要在当前本地目录中查找的内容,需要用完整路径重写,即http://services.www.gov.qa/TV/hukoomi/scripts/hukoomi_combined_js.js