Here is an example sheet: http://www.baseball-reference.com/te...-batting.shtml
When scraping my data is coming out all vertically (all in one column). I'm using ruby. Basically my idea was that when it runs through the html and identifies a player link (since all player names include an href) to then tell the program to start a new row/column in the excel spreadsheet. I suppose my question regards the best way to alter my coding to format these numbers into something that resembles the display on the website.
Current Script:
require 'nokogiri'
require 'open-uri'
require 'csv'
doc = Nokogiri::HTML(open('http://www.baseball-reference.com/teams/ARI/2011-batting.shtml'))
stats = Array.new
doc.css('tbody > tr > td').each do |stat|
stats << stat.content
end
(0..stats.length - 1).each do |index|
puts "stat: #{stats[index]**"
puts ""
end
CSV.open("losol.csv", "wb") do |row|
row << ["stat"]
(0..stats.length - 1).each do |index|
row << [stats[index]]
end
end
When scraping my data is coming out all vertically (all in one column). I'm using ruby. Basically my idea was that when it runs through the html and identifies a player link (since all player names include an href) to then tell the program to start a new row/column in the excel spreadsheet. I suppose my question regards the best way to alter my coding to format these numbers into something that resembles the display on the website.
Current Script:
require 'nokogiri'
require 'open-uri'
require 'csv'
doc = Nokogiri::HTML(open('http://www.baseball-reference.com/teams/ARI/2011-batting.shtml'))
stats = Array.new
doc.css('tbody > tr > td').each do |stat|
stats << stat.content
end
(0..stats.length - 1).each do |index|
puts "stat: #{stats[index]**"
puts ""
end
CSV.open("losol.csv", "wb") do |row|
row << ["stat"]
(0..stats.length - 1).each do |index|
row << [stats[index]]
end
end