How should I organize this data?

Hi Guys,

new to RoR but I’ve been stuck on this problem for a few days now. So
goal
is to scrape this data

http://lol.esportspedia.com/wiki/Riot_League_Championship_Series/North_America/2015_Season/Summer_Season/Picks_and_Bans

  • and then organize it in the following format

    • the teams involved (top left, top right columns)
    • the match result (1,0)
    • the bans → relational to the team
    • the picks → relational to the team
      • the pick sequence
        • goes from 1-10, left picks 1st, right picks 2nd,3rd, left
          picks
          4th n 5th (pattern goes to 10)

currently using the Nokogiri gem and was able to scrape the data with
the
following code (saved the html and parsed it locally)

require ‘rubygems’
require ‘nokogiri’
require ‘open-uri’
require ‘csv’

f = File.open(“napb.html”)

doc = Nokogiri::XML(open(f))
CSV.open(“file21.csv”, “wb”) do |data|
doc.css(‘table.prettytable > *’).search(‘tr’).each do |tr|
data << tr.search(‘td’).map(&:text)

end
end

I’ve been trying many different ways to put the data into arrays but I
haven’t had much success. Anyone can point me in the right direction?

Thanks a bunch
Aries

Well I am definitely not a Nokogiri expert, but I think that your first
issue may be that you are opening your HTML as XML. I think that doc =
Nokogiri::HTML(open(f)) might be better… Then I am a little worried
about your iteration structure.

doc… get the HTML
CSV.open … open the csv file
Then for each row as provide by data, send to file doc.css result…

Pretty sure that you want to get doc, then for each
doc.css('table.prettytable write to csv…

If I were you, I would first test my abilities to learn the content of
doc,
eg, napb.html. Then I would try writing to csv.

Liz