Rails 1.9.3

For http://en.wikipedia.org/wiki/List_of_airports_by_IATA_code:_A
I would like to make a list of airport names using Nokogiri.

The following code seems to work but it does not insert "\n" as I wish.

Can you tell me why?



require 'open-uri'
require 'nokogiri'

test_url =
"http://en.wikipedia.org/wiki/List_of_airports_by_IATA_code:_A"

url_list_file = "list_page_url.txt"
test_xpath = "//tr"
output_file = "list_airport_names_wiki_url.txt"

test = Nokogiri::HTML(open(test_url))
File.open(output_file, "a") {|f|
  test.xpath(test_xpath).each do |e|
    f.write e.xpath("//td[3]/a").text  + "\n"  #### HERE!!! ####
  end
}

-- 
Posted via http://www.ruby-forum.com/.