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






On Friday, July 10, 2015 at 9:46:11 AM UTC-4, Aries Gao wrote:
>
> 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
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/ca80d2ed-e163-4525-8fa8-83f6f768a155%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to