I would like to collect and store all this info into an array.
I have the following, how should I refactor this?
require 'rubygems'
require 'nokogiri'
require 'open-uri'
@urls = %w{http://url_01.com http://url_02.com http://url_03.com}
@link_01_arr = []
@link_02_arr = []
@link_03_arr = []
link_01 = Nokogiri::HTML(open("#{@urls[0]}"))
@link_01_arr[0] = link_01.at("title").inner_html
@link_01_arr[1] = link_01.at(".content").inner_html
@link_01_arr[2] = link_01.at(".date").inner_html
I tried doing this instead but it turned out significantly slower. i guess because there is more request this way.
@urls = %w{http://url_01.com http://url_02.com http://url_03.com}
@titles_arr = @urls.map do |url|
Nokogiri::HTML(open(url)).at("title").inner_html
end
@content_arr = @urls.map do |url|
Nokogiri::HTML(open(url)).at(".content").inner_html
end
@date_arr = @urls.map do |url|
Nokogiri::HTML(open(url)).at(".date").inner_html
end