我试图添加一个请求头,当用户使用weather.com在表单中搜索机场代码时生成。我已经成功地请求了第一页,但我需要帮助弄清楚如何在当前URL的末尾添加搜索查询字符串。
查询字符串为search?where=phx&start_with=1&search_loc_type=9&x=5&y=13
。phx
为机场代码。
我正试图找出如何添加这个查询字符串,例如,search?where="Airport_variable".&start_with=1&search_loc_type=9&x=5&y=13
。
因此,当一个人输入机场代码时,它会被weather.com服务器获取并添加到搜索查询中,并显示基于该查询的搜索结果。
有人能帮帮我吗?
到目前为止我写的是:
<?php
$URL = "http://www.weather.com/activities/travel/businesstraveler/";
$chwnd = curl_init();
curl_setopt($chwnd, CURLOPT_URL,$URL);
curl_setopt($chwnd, CURLOPT_VERBOSE, 1);
curl_setopt($chwnd, CURLOPT_POST, 1);
curl_setopt($chwnd, CURLOPT_POSTFIELDS, TRUE);
$returned = curl_exec($chwnd);
curl_close ($chwnd);
// /search?where=bhm&start_with=1&search_loc_type=9&x=0&y=0
?>
好吧-如果这是您的最后查询search?where=phx&start_with=1&search_loc_type=9&x=5&y=13
,那么只需按照您喜欢的方式组装它:
//take the paremeter: (using post ?! )
$Airport_variable = $_POST['where'];
$url = "http://www.weather.com/activities/travel/businesstraveler/";
//quertstring:
$url .= 'search?where=' . $Airport_variable . '&start_with=1&search_loc_type=9&x=5&y=13';
$chwnd = curl_init();
curl_setopt($chwnd, CURLOPT_URL,$url);
.
.
.