D
Derek Cannon
Hello everyone! I'm having some trouble with pushing an array to another
array. Maybe this is an easy fix that I'm just not seeing? Here's my
code:
require 'nokogiri'
require 'open-uri'
url = 'C:\\users\\derek\\desktop\\Schedule2.html'
doc = Nokogiri::HTML(open(url))
raw_course_list = Array.new
temp = Array.new
doc.css("tr").each { |row| # Search through every row
row.css("td").each { |column|
temp.push(column.text.strip)
}
# puts temp.class #=> Array
# puts temp.size #=> 20
# puts temp[7] # E.g. => "Intro to Financial Accounting"
raw_course_list.push(temp)
# puts "raw_course_list[0]: " + raw_course_list[0].to_s # ****
Always returns the last temp pushed, not what should be at [0] (the
first array ever pushed) ****
# print "raw_course_list.size: ", raw_course_list.size, "\n" #
Correctly increases +1 each push
temp.clear
}
puts raw_course_list.each { |i| puts i.to_s} # **** Prints out line
after line of empty arrays ****
array. Maybe this is an easy fix that I'm just not seeing? Here's my
code:
require 'nokogiri'
require 'open-uri'
url = 'C:\\users\\derek\\desktop\\Schedule2.html'
doc = Nokogiri::HTML(open(url))
raw_course_list = Array.new
temp = Array.new
doc.css("tr").each { |row| # Search through every row
row.css("td").each { |column|
temp.push(column.text.strip)
}
# puts temp.class #=> Array
# puts temp.size #=> 20
# puts temp[7] # E.g. => "Intro to Financial Accounting"
raw_course_list.push(temp)
# puts "raw_course_list[0]: " + raw_course_list[0].to_s # ****
Always returns the last temp pushed, not what should be at [0] (the
first array ever pushed) ****
# print "raw_course_list.size: ", raw_course_list.size, "\n" #
Correctly increases +1 each push
temp.clear
}
puts raw_course_list.each { |i| puts i.to_s} # **** Prints out line
after line of empty arrays ****