Hi
I am new programmer to Ruby. Just 1 days old. I do have some
background in java.
I am having a problem that is troubling me since yesterday and having
spend several hours on it, I still dont have any idea.
CODE WORKING GREAT BELOW
require ‘rubygems’
require ‘hpricot’
require ‘open-uri’
page = Hpricot(open(“http://finance.google.com/finance/historical?
q=ORCL&histperiod=weekly&start=01&num=2”))
page.search(“#prices”).each do |timesection|
values=timesection.search("td")
datePointValue = {
"date" => values[0].inner_html,
"open" => values[1].inner_html,
"high" => values[2].inner_html,
"low" => values[3].inner_html,
"close" => values[4].inner_html,
"volume" => values[5].inner_html
}
datePointValue.each do |key, value|
puts key + " - " + value
end
end
But when I add a loop and change the code as follows. It gives me
error message
UPDATED CODE - NOT WORKING -
page = Hpricot(open(“http://finance.google.com/finance/historical?
q=ORCL&histperiod=weekly&start=01&num=1”))
page.search(“#prices”).each do |timesection|
timesection.search("tr").each do |datePointSets|
values = datePointSets.search("td")
datePointValue = {
"date" => values[0].inner_html,
"open" => values[1].inner_html,
"high" => values[2].inner_html,
"low" => values[3].inner_html,
"close" => values[4].inner_html,
"volume" => values[5].inner_html
}
datePointValue.each do |key, value|
puts key + " - " + value
end
end
end
ERROR MESSAGE
htest.rb:14: undefined method inner_html' for nil:NilClass (NoMethodError) from htest.rb:10:in
each’
from htest.rb:10
from htest.rb:8:in `each’
from htest.rb:8
Kindly suggest.