From: Vikash Kumar Date: 2007-01-15T20:46:17+09:00 Subject: Re: storing values in variables >> def parse_html(data,tag) >> return data.scan(%r{<#{tag}\s*.*?>(.*?)}im).flatten >> end > Have you looked at hpricot? (Google it.) With it, your code'll look > something like: > def parse_html(el, tag) > el.search("//#{tag}") > end > Get to know Array#map. Your code'll look something like: > output = parse_html(page, 'table').map do |table| > parse_html(table, 'tr').map do |row| > parse_html(row,'td').map do |cell| > cell.inner_html.gsub(%r{<.*?>},"") > end > end > end > > >> puts "#{"\t" * tab}}" >> end >> n += 1 >> end >> end > 1. Array#each_with_index will keep track of n for you. > 2. Array#inspect or Kernel#p will print the array in a readable format. > > Otherwise, I think we need more information. > Devin I am new to hpricot, but I tried this require 'watir' require 'hpricot' require 'open-uri' page = Hpricot(open("http://kvcrpf.org/achievements.htm")) def parse_html(e1,tag) e1.search("//#{tag}}") end output = parse_html(page, 'table').map do |table| parse_html(table, 'tr').map do |row| parse_html(row,'td').map do |cell| cell.inner_html.gsub(%r{<.*?>},"") end end end parse_nested_array(output[2][4]) By running this code, I get the following error: c:/ruby/lib/ruby/gems/1.8/gems/hpricot-0.4-mswin32/lib/hpricot/traverse.rb:110:in `search': undefined method `[]=' for # (NoMethodError) from test1.rb:30:in `parse_html' from test1.rb:33 Please help me in solving this. Also, what should be the approach to parse data from an open page, i.e. is there is something like page = Hpricot(attach("http://kvcrpf.org/achievements.htm")) Thanks for your help Vikash -- Posted via http://www.ruby-forum.com/.