Ja sam parsirao onda samo ove za koje imaju planovi leta u njihovoj bazi podataka.
Odlično je što imaju i koordinate.
PHP kôd:
if($action == "parse.code"){
$html = file_get_html("http://timetables.oag.com/BNX/LetterSearch.asp?letter=$q");
$i = 0;
foreach($html->find("table[cellspacing=1] tr") as $tr){
$a = $tr->find("td a", 0)->href;
preg_match("#\('(.*?)', '(.*?)'\)#", $a, $matches);
unset($matches[0]);
$city = $matches[1];
$code = $matches[2];
$country = $tr->find("td", 2)->plaintext;
$city = addslashes($city);
$country = addslashes($country);
echo("INSERT INTO airports(code,city,country) VALUES('$code','$city','$country');<br />");
$i++;
}
}
Ovaj world-airport-codes.com je malo komplikovaniji pa nisam htio da petljam ali evo i za njega...
PHP kôd:
if($action == "parse.codes"){
$html = file_get_html("http://www.world-airport-codes.com/search/?criteria=$q");
foreach($html->find("table.results tr") as $tr){
$rows[] = $tr->plaintext;
}
unset($rows[0]);
$count = count($rows);
for($i = 1; $i <= $count; $i++){
if($i % 2 == 0) $results[] = $rows[$i];
}
foreach($results as $key => $value){
$value = str_replace(array("\t", "\n"), ";", $value);
$value = preg_replace("#(;){1,}#is", ";", $value);
$results[$key] = trim($value, ";");
}
print_r($results);
}