我正在尝试从this page检索表单。我设置了cookie并发送了表单数据,但我回来的都是无效页面。
$ckfile = tempnam ("/tmp", "CURLCOOKIE");
$ch = curl_init ("http://services.www.gov.qa/TV/process/TV/TV_TrafficViolation?lang=en¬loggedin=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);
答案 0 :(得分:0)
在我看来,一个问题是你要返回的页面包含大量的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