0

我正在尝试使用 cURL 或 GET 请求来检索从表单提交到公司网站的结果

我正在尝试使用 php 脚本从 aa.com 获取航班状态结果。

该表单位于https://www.aa.com/homePage.do >> 航班状态(按航班号和日期搜索),当您在表单上输入数据时,您将获得航班状态和地址窗口中的 URL好像:

https://www.aa.com/travelInformation/flights/status/detail?search=AA|1698|2019,1,23&ref=search

其中 1698 是航班号,2019,1,23 是在日期下拉菜单中选择 1 月 23 日星期三后的 url 格式日期。

我曾尝试在页面中同时使用 file_get_contents,例如:

    $flight_data = file_get_contents("https://www.aa.com/travelInformation/flights/status/detail?search=AA|$flight|$formatted_date|&ref=search");

其中 $flight 和 $formatted date 被我网站的表单输入替换。

    $flight_data = file_get_contents("https://www.aa.com/travelInformation/flights/status/detail?search=AA|1698|2019,01,23|&ref=search");

当它被处理并将结果打印到屏幕上时,它不包含航班状态信息,它只包含一些通用输出。

当我使用 cURL 尝试获取数据时:

    $target = 'https://www.aa.com/travelInformation/flights/status/lookup';

$agent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5";

//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
    $post_items[] = $key . '=' . $value;
}

//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);

//create cURL connection
$ch = curl_init();

//set options
curl_setopt($ch, CURLOPT_URL, $target);
curl_setopt($ch, CURLOPT_REFERER, $ref);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

//set data to be posted
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_POST, true);

//perform our request
$flight_data = curl_exec($ch);

//show information regarding the request
print_r(curl_getinfo($ch));
echo curl_errno($ch) . '-' .
    curl_error($ch);

//close the connection
curl_close($ch);*/

print $flight_data;

我得到相同的通用输出。

我期望得到的是页面的来源,就好像我真的去了 aa.com 并在他们的表格上输入了航班信息一样。然后我想解析该结果以获取在给定日期具有给定航班号的所有航班。

提前致谢。

4

0 回答 0