Skip to content

Instantly share code, notes, and snippets.

@valdeir2000
Last active September 11, 2019 15:00
Show Gist options
  • Save valdeir2000/2796fe3dcb6115be8c3b28a1b7702f57 to your computer and use it in GitHub Desktop.
Save valdeir2000/2796fe3dcb6115be8c3b28a1b7702f57 to your computer and use it in GitHub Desktop.
Stackoverflow #278574
curl -LX POST \
-H 'Content-Type: application/x-www-form-urlencoded' \
-b 'cookies.txt' \
-d '__EVENTTARGET=ControlGroupSearch%24LinkButtonSubmit&__VIEWSTATE=%2FwEPDwUBMGRk8HVTGURCOI8ogJjuxnKVJYjGv9I%3D&loginDomain=AZUL_LOGIN&NavigationHeaderInputFlightSearchView%24MemberLoginFlightSearchView%24TextBoxUserID=&NavigationHeaderInputFlightSearchView%24MemberLoginFlightSearchView%24PasswordFieldPassword=&ControlGroupSearch%24SearchMainSearchView%24RadioButtonMarketStructure=RoundTrip&ControlGroupSearch%24SearchMainSearchView%24TextBoxMarketOrigin1=Salvador%20(SSA)&ControlGroupSearch%24SearchMainSearchView%24CheckBoxUseMacOrigin1=&hdfSearchCodeDeparture1=1N&ControlGroupSearch%24SearchMainSearchView%24TextBoxMarketDestination1=Natal%20(NAT)&ControlGroupSearch%24SearchMainSearchView%24CheckBoxUseMacDestination1=&hdfSearchCodeArrival1=1N&departure1=01%2F03%2F2018&ControlGroupSearch%24SearchMainSearchView%24DropDownListMarketDay1=01&ControlGroupSearch%24SearchMainSearchView%24DropDownListMarketMonth1=2018-03&arrival=07%2F03%2F2018&ControlGroupSearch%24SearchMainSearchView%24DropDownListMarketDay2=07&ControlGroupSearch%24SearchMainSearchView%24DropDownListMarketMonth2=2018-03&origin2=&ControlGroupSearch%24SearchMainSearchView%24TextBoxMarketOrigin2=&ControlGroupSearch%24SearchMainSearchView%24CheckBoxUseMacOrigin2=&hdfSearchCodeDeparture2=&destination2=&ControlGroupSearch%24SearchMainSearchView%24TextBoxMarketDestination2=&ControlGroupSearch%24SearchMainSearchView%24CheckBoxUseMacDestination2=&hdfSearchCodeArrival2=&departure2=&ControlGroupSearch%24SearchMainSearchView%24DropDownListPassengerType_ADT=1&ControlGroupSearch%24SearchMainSearchView%24DropDownListPassengerType_CHD=0&ControlGroupSearch%24SearchMainSearchView%24DropDownListPassengerType_INFANT=0&faretypes=R&ControlGroupSearch%24SearchMainSearchView%24DropDownListSearchBy=columnView&ControlGroupSearch%24SearchMainSearchView%24DropDownListFareTypes=R&searchTypeMyReservation=booking-code&origin-depbutton-0003%20skin-0008%20text--0001%20ps-right%20ps-bottomarture=&departure=&destination-arrival=&origin=&from=&destination=&to=&flightNumber=&date=S%C3%A1bado%2C%2024%2F02%2F2018' \
https://<dominio-da-empresa>.com.br/Search.aspx > index.html
sed -ri 's/(<head>)/\1<base href="https:\/\/<dominio-da-empresa>.com.br\/" \/>/g' index.html
{
"id": "9d080934-2035-0e69-6145-b0b679eb03a4",
"name": "StackOverflow #278574",
"description": "",
"order": [],
"folders": [{
"name": "<empresa>",
"description": "",
"collectionId": "9d080934-2035-0e69-6145-b0b679eb03a4",
"order": ["3e323f25-6cfa-e9ae-c93e-998220160fe6"],
"owner": "143755",
"folders_order": [],
"auth": null,
"id": "77fbf552-9c36-97d8-aff3-455659cac79a"
}, {
"name": "Gol",
"description": "",
"collectionId": "9d080934-2035-0e69-6145-b0b679eb03a4",
"order": ["e97f53bb-52a3-9058-d85a-7c4b20f07c4e", "102cb035-6cb6-92d3-1806-7e0c9017c690"],
"owner": "143755",
"folders_order": [],
"auth": null,
"id": "3c2fffe9-5d15-11b3-0ff7-4118f3e0d7e1"
}],
"folders_order": ["3c2fffe9-5d15-11b3-0ff7-4118f3e0d7e1", "77fbf552-9c36-97d8-aff3-455659cac79a"],
"timestamp": 1519450703005,
"owner": "143755",
"public": false,
"events": [],
"variables": [],
"auth": null,
"requests": [{
"id": "102cb035-6cb6-92d3-1806-7e0c9017c690",
"headers": "X-API-KEY: aJqPU7xNHl9qN3NVZnPaJ208aPo2Bh2p2ZV844tw\n",
"headerData": [{
"key": "X-API-KEY",
"value": "aJqPU7xNHl9qN3NVZnPaJ208aPo2Bh2p2ZV844tw",
"description": "",
"enabled": true
}],
"url": "https:\/\/flightavailability.blue.smiles.com.br\/searchflights?adults=1&children=0&departureDate=2018-03-31&destinationAirportCode=BSB&forceCongener=false&infants=0&memberNumber=&originAirportCode=REC",
"queryParams": [{
"key": "adults",
"value": "1",
"equals": true,
"description": "",
"enabled": true
}, {
"key": "children",
"value": "0",
"equals": true,
"description": "",
"enabled": true
}, {
"key": "departureDate",
"value": "2018-03-31",
"equals": true,
"description": "",
"enabled": true
}, {
"key": "destinationAirportCode",
"value": "BSB",
"equals": true,
"description": "",
"enabled": true
}, {
"key": "forceCongener",
"value": "false",
"equals": true,
"description": "",
"enabled": true
}, {
"key": "infants",
"value": "0",
"equals": true,
"description": "",
"enabled": true
}, {
"key": "memberNumber",
"value": "",
"equals": true,
"description": "",
"enabled": true
}, {
"key": "originAirportCode",
"value": "REC",
"equals": true,
"description": "",
"enabled": true
}],
"pathVariables": [],
"pathVariableData": [],
"events": [],
"auth": null,
"method": "GET",
"collectionId": "9d080934-2035-0e69-6145-b0b679eb03a4",
"data": null,
"dataMode": "params",
"name": "Captura os dados",
"description": "",
"descriptionFormat": "html",
"time": 1519450839187,
"version": 2,
"responses": [],
"folder": "3c2fffe9-5d15-11b3-0ff7-4118f3e0d7e1",
"currentHelper": null,
"helperAttributes": null
}, {
"id": "3e323f25-6cfa-e9ae-c93e-998220160fe6",
"headers": "Content-Type: application\/x-www-form-urlencoded\n",
"headerData": [{
"key": "Content-Type",
"value": "application\/x-www-form-urlencoded",
"description": "",
"enabled": true
}],
"url": "https:\/\/<dominio-da-empresa>.com.br\/Search.aspx",
"queryParams": [],
"events": [],
"pathVariables": [],
"pathVariableData": [],
"method": "POST",
"data": [{
"key": "__EVENTTARGET",
"value": "ControlGroupSearch$LinkButtonSubmit",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "__VIEWSTATE",
"value": "\/wEPDwUBMGRk8HVTGURCOI8ogJjuxnKVJYjGv9I=",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "loginDomain",
"value": "AZUL_LOGIN",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "NavigationHeaderInputFlightSearchView$MemberLoginFlightSearchView$TextBoxUserID",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "NavigationHeaderInputFlightSearchView$MemberLoginFlightSearchView$PasswordFieldPassword",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$RadioButtonMarketStructure",
"value": "RoundTrip",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$TextBoxMarketOrigin1",
"value": "Salvador (SSA)",
"description": "Aeroporto de Partida",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$CheckBoxUseMacOrigin1",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "hdfSearchCodeDeparture1",
"value": "1N",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$TextBoxMarketDestination1",
"value": "Natal (NAT)",
"description": "Aeroporto de Destino #1",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$CheckBoxUseMacDestination1",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "hdfSearchCodeArrival1",
"value": "1N",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "departure1",
"value": "01\/03\/2018",
"description": "Data de Partida",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$DropDownListMarketDay1",
"value": "01",
"description": "Dia da data de partida",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$DropDownListMarketMonth1",
"value": "2018-03",
"description": "Ano e m\u00eas de partida",
"type": "text",
"enabled": true
}, {
"key": "arrival",
"value": "07\/03\/2018",
"description": "Data do Retorno",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$DropDownListMarketDay2",
"value": "07",
"description": "Dia da data de retorno",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$DropDownListMarketMonth2",
"value": "2018-03",
"description": "Ano e m\u00eas de retorno",
"type": "text",
"enabled": true
}, {
"key": "origin2",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$TextBoxMarketOrigin2",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$CheckBoxUseMacOrigin2",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "hdfSearchCodeDeparture2",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "destination2",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$TextBoxMarketDestination2",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$CheckBoxUseMacDestination2",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "hdfSearchCodeArrival2",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "departure2",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$DropDownListPassengerType_ADT",
"value": "1",
"description": "N\u00famero de adultos",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$DropDownListPassengerType_CHD",
"value": "0",
"description": "N\u00famero de crian\u00e7as",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$DropDownListPassengerType_INFANT",
"value": "0",
"description": "N\u00famero de beb\u00eas",
"type": "text",
"enabled": true
}, {
"key": "faretypes",
"value": "R",
"description": "Tipo de Tarifa",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$DropDownListSearchBy",
"value": "columnView",
"description": "Buscar por...",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$DropDownListFareTypes",
"value": "R",
"description": "Tipo de tafira (R = Reais | TP = Pontos + Reais | TD = Pontos)",
"type": "text",
"enabled": true
}, {
"key": "searchTypeMyReservation",
"value": "booking-code",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "origin-depbutton-0003 skin-0008 text--0001 ps-right ps-bottomarture",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "departure",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "destination-arrival",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "origin",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "from",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "destination",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "to",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "flightNumber",
"value": "",
"description": "",
"type": "text",
"enabled": true
}, {
"key": "date",
"value": "S\u00e1bado, 24\/02\/2018",
"description": "Data da requisi\u00e7\u00e3o",
"type": "text",
"enabled": true
}, {
"key": "ControlGroupSearch$SearchMainSearchView$FlexibleSearch",
"value": "on",
"description": "Habilia busca por hor\u00e1rios flex\u00edveis. Para desabilitar, basta n\u00e3o enviar.",
"type": "text",
"enabled": false
}],
"dataMode": "urlencoded",
"version": 2,
"auth": null,
"time": 1519471871930,
"name": "<nome-da-empresa>",
"description": null,
"collectionId": "9d080934-2035-0e69-6145-b0b679eb03a4",
"responses": [],
"currentHelper": null,
"helperAttributes": null
}, {
"id": "e97f53bb-52a3-9058-d85a-7c4b20f07c4e",
"headers": "",
"headerData": [{
"key": "",
"value": "",
"description": "",
"enabled": true
}],
"url": "https:\/\/flightavailability.blue.smiles.com.br\/searchflights?adults=1&children=0&departureDate=2018-03-31&destinationAirportCode=BSB&forceCongener=false&infants=0&memberNumber=&originAirportCode=REC",
"queryParams": [{
"key": "adults",
"value": "1",
"equals": true,
"description": "",
"enabled": true
}, {
"key": "children",
"value": "0",
"equals": true,
"description": "",
"enabled": true
}, {
"key": "departureDate",
"value": "2018-03-31",
"equals": true,
"description": "",
"enabled": true
}, {
"key": "destinationAirportCode",
"value": "BSB",
"equals": true,
"description": "",
"enabled": true
}, {
"key": "forceCongener",
"value": "false",
"equals": true,
"description": "",
"enabled": true
}, {
"key": "infants",
"value": "0",
"equals": true,
"description": "",
"enabled": true
}, {
"key": "memberNumber",
"value": "",
"equals": true,
"description": "",
"enabled": true
}, {
"key": "originAirportCode",
"value": "REC",
"equals": true,
"description": "",
"enabled": true
}],
"pathVariables": [],
"pathVariableData": [],
"events": [],
"auth": null,
"method": "OPTIONS",
"collectionId": "9d080934-2035-0e69-6145-b0b679eb03a4",
"data": null,
"dataMode": "params",
"name": "\"Pede\" Autoriza\u00e7\u00e3o",
"description": "",
"descriptionFormat": "html",
"time": 1519450801891,
"version": 2,
"responses": [],
"folder": "3c2fffe9-5d15-11b3-0ff7-4118f3e0d7e1",
"currentHelper": null,
"helperAttributes": null
}]
}
<?php
/* URL da requisição */
$url = 'https://<dominio-da-empresa>.com.br/Search.aspx';
/**
* Campos com as informações a sem enviadas
* Para identificar os campos acesse < o arquivo postman.json >
*/
$fields = [
'__EVENTTARGET' => 'ControlGroupSearch$LinkButtonSubmit',
'__VIEWSTATE' => '/wEPDwUBMGRk8HVTGURCOI8ogJjuxnKVJYjGv9I=',
'loginDomain' => 'AZUL_LOGIN',
'NavigationHeaderInputFlightSearchView$MemberLoginFlightSearchView$TextBoxUserID' => '',
'NavigationHeaderInputFlightSearchView$MemberLoginFlightSearchView$PasswordFieldPassword' => '',
'ControlGroupSearch$SearchMainSearchView$RadioButtonMarketStructure' => 'RoundTrip',
'ControlGroupSearch$SearchMainSearchView$TextBoxMarketOrigin1' => 'Salvador (SSA)',
'ControlGroupSearch$SearchMainSearchView$CheckBoxUseMacOrigin1' => '',
'hdfSearchCodeDeparture1' => '1N',
'ControlGroupSearch$SearchMainSearchView$TextBoxMarketDestination1' => 'Natal (NAT)',
'ControlGroupSearch$SearchMainSearchView$CheckBoxUseMacDestination1' => '',
'hdfSearchCodeArrival1' => '1N',
'departure1' => '01/03/2018',
'ControlGroupSearch$SearchMainSearchView$DropDownListMarketDay1' => '01',
'ControlGroupSearch$SearchMainSearchView$DropDownListMarketMonth1' => '2018-03',
'arrival' => '07/03/2018',
'ControlGroupSearch$SearchMainSearchView$DropDownListMarketDay2' => '07',
'ControlGroupSearch$SearchMainSearchView$DropDownListMarketMonth2' => '2018-03',
'origin2' => '',
'ControlGroupSearch$SearchMainSearchView$TextBoxMarketOrigin2' => '',
'ControlGroupSearch$SearchMainSearchView$CheckBoxUseMacOrigin2' => '',
'hdfSearchCodeDeparture2' => '',
'destination2' => '',
'ControlGroupSearch$SearchMainSearchView$TextBoxMarketDestination2' => '',
'ControlGroupSearch$SearchMainSearchView$CheckBoxUseMacDestination2' => '',
'hdfSearchCodeArrival2' => '',
'departure2' => '',
'ControlGroupSearch$SearchMainSearchView$DropDownListPassengerType_ADT' => '1',
'ControlGroupSearch$SearchMainSearchView$DropDownListPassengerType_CHD' => '0',
'ControlGroupSearch$SearchMainSearchView$DropDownListPassengerType_INFANT' => '0',
'faretypes' => 'R',
'ControlGroupSearch$SearchMainSearchView$DropDownListSearchBy' => 'columnView',
'ControlGroupSearch$SearchMainSearchView$DropDownListFareTypes' => 'R',
'searchTypeMyReservation' => 'booking-code',
'origin-depbutton-0003 skin-0008 text--0001 ps-right ps-bottomarture' => '',
'departure' => '',
'destination-arrival' => '',
'origin' => '',
'from' => '',
'destination' => '',
'to' => '',
'flightNumber' => '',
'date' => 'Sábado, 24/02/2018',
];
/* Inicializa a biblioteca cURL */
$ch = curl_init();
/* Define as configurações da requisição */
curl_setopt_array($ch, [
/* Informa a URL */
CURLOPT_URL => $url,
/* Informa que deseja capturar o retorno */
CURLOPT_RETURNTRANSFER => true,
/* Permite o redirecionamento */
CURLOPT_FOLLOWLOCATION => true,
/* Informa que o tipo da requisição é POST */
CURLOPT_POST => true,
/* Converte os dados para application/x-www-form-urlencoded */
CURLOPT_POSTFIELDS => http_build_query($fields),
/* Habilita a escrita de Cookies */
CURLOPT_COOKIEJAR => 'cookies.txt',
/* Desabilita a verificação do SSL, caso você possua, pode deixar habilitado */
CURLOPT_SSL_VERIFYPEER => false,
]);
/* Executa a requisição e captura o retorno */
$response = curl_exec($ch);
/* Captura eventuais erros */
$error = curl_error($ch);
/* Captura a informação da requisição */
$info = curl_getinfo($ch);
/* Fecha a conexão */
curl_close($ch);
/* Instancia o objeto DOMDocument para utilizamos a busca */
$dom = new DOMDocument();
/* Carrega a resposta e oculta os erros do HTML */
@$dom->loadHTML( $response );
/* Instancia o objeto DOMXPath para busca através expressões XPATH */
$xpath = new DOMXPath($dom);
/* Captura o local de partida */
$origin = trim($xpath->query("//section[@id='select-flight']//div[@id='box-depart-flights']//span[@class='dep-airport']")
->item(0)->textContent);
/* Captura o local de destino */
$destination = trim($xpath->query("//section[@id='select-flight']//div[@id='box-depart-flights']//span[@class='arr-airport']")
->item(0)->textContent);
/* Variável responsável por armazenar os dados do voo */
$data = [];
/* Realiza uma busca dos elementos TR da tabela "tbl-depart-flights" (Local onde fica os voo de ida) */
$flights = $xpath->query("//table[@id='tbl-depart-flights']//tbody/tr");
/* Percorre todos os elementos encontrados */
for ($i = 0; $i <= $flights->length; $i++) {
/* Captura o número do voo e o total de escala */
$flightNumberAndStopover = $xpath->query(".//span[@id='button-flyout-4']//span", $flights->item($i));
/* Captura o horário de partida e chegada */
$schedule = trim( $xpath->query(".//div[@class='schedule container']", $flights->item($i))->item(0)->textContent );
/* Captura o preço com bagagem */
$price = $xpath->query(".//td[@class='flex']//div[@class='price']", $flights->item($i))->item(0);
$price = $price->ownerDocument->saveHTML($price);
/* Captura o preço SEM bagagem */
$promo = $xpath->query(".//td[@class='promo']//div[@class='price']", $flights->item($i))->item(0);
$promo = $promo->ownerDocument->saveHTML($promo);
/* Armazena os dados */
$data[] = [
'flight_number' => trim($flightNumberAndStopover->item(0)->textContent),
'stopover' => trim($flightNumberAndStopover->item(1)->textContent),
'schedule' => $schedule,
'price' => $price,
'promo' => $promo
];
}
?>
<link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/pure-min.css" integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w" crossorigin="anonymous">
<table class="pure-table">
<caption>Voo de Ida<br><?php echo "De {$origin} para {$destination}" ?></caption>
<thead>
<tr>
<th>Voo</th>
<th>Escala</th>
<th>Horário</th>
<th>Preço</th>
<th>Promo</th>
</tr>
</thead>
<tbody>
<!-- Percorre todo o array criado -->
<?php foreach($data as $flight_info): ?>
<tr>
<!-- Concate o endereço do site com o caminho da imagem -->
<td><?php echo $flight_info['flight_number'] ?></td>
<!-- Exibe nome da moeda -->
<td><?php echo $flight_info['stopover'] ?></td>
<!-- Exibe valor da compra -->
<td><?php echo $flight_info['schedule'] ?></td>
<!-- Exibe valor da venda -->
<td><?php echo $flight_info['price'] ?></td>
<td><?php echo $flight_info['promo'] ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<pre><?php var_export( $error ); ?></pre>
<pre><?php var_export( $info ); ?></pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment