0

ブラジルでのフライトのフライト監視ソフトウェアを開発していますが、Web サイトからフライト データを正常に受信するのに問題があります。それは ASP.NET にあり、実際にデータを表示する前に、複数の要求を満たす必要があると思います。

私はすでに ASP.NET 固有の変数 (EVENTVALIDATION や VIEWSTATE など) を取得しており、複数の要求 (1 つは空港を送信し、もう 1 つは投稿を送信) を送信していますが、それでもうまくいきません。

空港と航空会社を選択するページはhttp://voos.infraero.gov.br/voos/index.aspxですが、データはここに表示されていますhttp://voos.infraero.gov.br/voos/index_2 .aspx .

まだデバッグ中のため、コードは最適化されていません。助けてくれてありがとう。

<?php

// Sets the server variables for this script
ini_set("max_execution_time", 0);
ini_set("error_reporting", E_ALL);
ini_set("default_charset", "utf-8");

// Sets the cookie
$cookie = dirname(__FILE__)."/cookies/cookiejar.txt";
$fp = fopen($cookie, "w");
fclose($fp);

// Slices the string to the the viewstate value
function GetViewState($result)
{
    $doc = new DOMDocument(); 
    $doc->loadHTML($result);  
    $nodes = $doc->getElementsByTagName('input');  

    for($i = 0; $i < $nodes->length; $i++)
    { 
        if ($nodes->item($i)->getAttribute('name') == "__VIEWSTATE")
        $viewstate = $nodes->item($i)->getAttribute('value'); 
    }

    return $viewstate;
}

// Slices the string to the the eventvalidation value
function GetEventValidation($result)
{
    $doc = new DOMDocument(); 
    $doc->loadHTML($result);  
    $nodes = $doc->getElementsByTagName('input');  

    for($i = 0; $i < $nodes->length; $i++)
    { 
        if ($nodes->item($i)->getAttribute('name') == "__EVENTVALIDATION")
        $eventvalidation = $nodes->item($i)->getAttribute('value');  
    }

    return $eventvalidation;
}

// Sends a request only to retrieve EVENTVALIDATION and VIEWSTATE values
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://voos.infraero.gov.br/voos/index.aspx");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_REFERER, "http://voos.infraero.gov.br/voos/index.aspx");
curl_setopt($ch, CURLOPT_VERBOSE, '1');
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
echo $result = curl_exec($ch);
$viewstate = GetViewState($result);
$eventvalidation = GetEventValidation($result);
/////////////////////////////////////////////////////////////////

// Sends the received VIEWSTATE and EVENTVALIDATION values, as well as the airport (SBCF)
$ch = curl_init();
$postfields = "ScriptManager1=update|aero_companias_aeroportos";
$postfields .= "&__EVENTTARGET=aero_companias_aeroportos";
$postfields .= "&__EVENTARGUMENT=";
$postfields .= "&__LASTFOCUS=";
$postfields .= "&__VIEWSTATE=".$viewstate;
$postfields .= "&__EVENTVALIDATION=".$eventvalidation;
$postfields .= "&pode_pesquisar_aeroporto=S";
$postfields .= "&aero_companias_aeroportos=SBCF";
$postfields .= "&txt_num_voo=";
$postfields .= "&txt_water_box_ClientState=";
//echo $postfields;
curl_setopt($ch, CURLOPT_URL, "http://voos.infraero.gov.br/voos/index.aspx");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_REFERER, "http://voos.infraero.gov.br/voos/index.aspx");
curl_setopt($ch, CURLOPT_VERBOSE, '1');
echo $result = curl_exec($ch);
$viewstate = GetViewState($result);
$eventvalidation = GetEventValidation($result);
/////////////////////////////////////////////////////////////////

// Sends the same as the previous request, plus the form
$postfields = "ScriptManager1=update|btnPesquisar";
$postfields .= "&__EVENTTARGET=";
$postfields .= "&__EVENTARGUMENT=";
$postfields .= "&__LASTFOCUS=";
$postfields .= "&__VIEWSTATE=".$viewstate;
$postfields .= "&__EVENTVALIDATION=".$eventvalidation;
$postfields .= "&pode_pesquisar_aeroporto=S";
$postfields .= "&aero_companias_aeroportos=SBCF";
$postfields .= "&aero_companias_companias=Selecione%20uma%20Companhia%20A%C3%A9rea";
$postfields .= "&txt_num_voo=";
$postfields .= "&txt_water_box_ClientState=";
$postfields .= "&btnPesquisar=Consultar%20Voos";
//echo $postfields;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://voos.infraero.gov.br/voos/index.aspx");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_REFERER, "http://voos.infraero.gov.br/voos/index.aspx");
curl_setopt($ch, CURLOPT_VERBOSE, '1');
echo $result = curl_exec($ch);
$viewstate = GetViewState($result);
$eventvalidation = GetEventValidation($result);
/////////////////////////////////////////////////////////////////

// Shows the page with the results
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://voos.infraero.gov.br/voos/index_2.aspx");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_REFERER, "http://voos.infraero.gov.br/voos/index.aspx");
curl_setopt($ch, CURLOPT_VERBOSE, '1');
echo $result = curl_exec($ch);
/////////////////////////////////////////////////////////////////

?>
4

0 に答える 0