Parsed from: Wikipedia.
Available on YAML or JSON format.
Data example:
- :airport_name: Charles de Gaulle International Airport (Roissy Airport) :complete_location: Paris, France :city: Paris :country: "France" :iata_code: CDG :icao_code: LFPG
Below is a snippet on how to parse this content using Hpricot.
doc = Hpricot(open "http://en.wikipedia.org/wiki/List_of_airports_by_IATA_code:_#{letter}")
doc.search('table.wikitable tr:not(:first-child):not(.sortbottom)').each do |tr_line|
# Iata, Icao, Airport name, Location served
line_records = (tr_line/'td').map{|el| ActionController::Base.helpers.strip_tags el.inner_html}
next if line_records[2].blank?
airport = {:iata_code => line_records[0],
:icao_code => line_records[1],
:airport_name => line_records[2],
:complete_location => line_records[3],
}
location_array = airport[:complete_location].split(',')
unless location_array.blank?
airport[:city] = location_array.first
airport[:country] = location_array.last
end
result << airport
end;
end;
Filed under: Data Extraction Tagged: | airport codes, hpricot, iata airport codes, icao codes, web scraping
Hello Vlad-Ionut Zloteanu
When i tried to parse the above JSON string in PHP , i got the error saying
“- Syntax error, malformed JSON”.
Could you please help me to resolve this?
Thanks in Advance !!