<?php
function scrapeFlights($origin, $destination, $date) {
$url = "https://w...content-available-to-author-only...t.com/search-flight?origin={$origin}&destination={$destination}&date={$date}";
// Initialize cURL
curl_setopt($ch, CURLOPT_USERAGENT
, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36');
// Execute cURL request
// Load HTML response into DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($response); // Use @ to suppress warnings for invalid HTML
$xpath = new DOMXPath($dom);
$flights = [];
// XPath query to find flight elements (adjust according to actual HTML structure)
$flightNodes = $xpath->query("//div[contains(@class, 'flight-list')]//div[contains(@class, 'flight-item')]");
foreach ($flightNodes as $node) {
$flight = [];
// Extract flight details (adjust these queries based on the actual HTML structure)
$flight['airline'] = $xpath->query(".//span[contains(@class, 'airline-name')]", $node)->item(0)->nodeValue ?? '';
$flight['price'] = $xpath->query(".//span[contains(@class, 'flight-price')]", $node)->item(0)->nodeValue ?? '';
$flight['departure'] = $xpath->query(".//span[contains(@class, 'departure-time')]", $node)->item(0)->nodeValue ?? '';
$flight['arrival'] = $xpath->query(".//span[contains(@class, 'arrival-time')]", $node)->item(0)->nodeValue ?? '';
if (!empty($flight['airline'])) { $flights[] = $flight;
}
}
return $flights;
}
// Example usage
$origin = 'JKT'; // Jakarta
$destination = 'SUB'; // Surabaya
$date = '2024-11-01'; // Flight date
$flightResults = scrapeFlights($origin, $destination, $date);
?>
PD9waHAKCmZ1bmN0aW9uIHNjcmFwZUZsaWdodHMoJG9yaWdpbiwgJGRlc3RpbmF0aW9uLCAkZGF0ZSkgewogICAgJHVybCA9ICJodHRwczovL3cuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLnQuY29tL3NlYXJjaC1mbGlnaHQ/b3JpZ2luPXskb3JpZ2lufSZkZXN0aW5hdGlvbj17JGRlc3RpbmF0aW9ufSZkYXRlPXskZGF0ZX0iOwoKICAgIC8vIEluaXRpYWxpemU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