Hi,
I am new to ruby and am trying to scrape a website table into a matrix,
I have been playing around with WWW::Mechanize and have had some success
getting the page, extracting the table I want and then separating the
result by table rows. The problem comes with then splitting it down by
table data, I am going through each result in the array to break it by
the tag, but my code appears to have zero effect!
The code I am using is below; any help in getting the table into a
matrix would be really appreciated.
Thanks
Adam
require ‘rubygems’
require ‘mechanize’
agent = WWW::Mechanize.new
agent.user_agent_alias = ‘Mac Safari’
page =
agent.get(“http://horses.sportinglife.com/Racecards/0,12495,215137,00.html").search("//table[@class=‘racecard_table’]”)
tablerows = page.search(“//tr”)
puts tablerows.length
finalresult = Array.new
tablerows.each do |tablerows|
finalresult << tablerows.search(“//td”)
end
puts finalresult.length