From: Robert Klemme Date: 2012-05-29T05:34:30+09:00 Subject: Re: faster CSV writing On Mon, May 28, 2012 at 9:21 PM, steven gre wrote: > trying to take scraped info business name address and phone# i can get > the values into a variable but it writes to 1 line in csv i,m not > concerned with headers but do want to write columns corectly.  I'm new > to butchering ruby but really like all the functions I've found/used so > far. > > here is the code i'm working with > > require 'rubygems' > require 'fastercsv' > require 'nokogiri' > require 'open-uri' > page = > Nokogiri::HTML(open("http://www.yellowpages.com/florida/auto-repair?q=auto+repair")) > bname = page.css("h3.business-name.fn.has-menu.org").text > addy = page.css("span.street-address").text > csz = page.css("span.city-state").text > count = page.css("p.result-count").text > count = count.gsub(/Results 1-30 of /,'') > phone = Array.new > phone = page.css("span.business-phone.phone").text > phone= phone.gsub(/\n/,'') > phone= phone.gsub(/ /,'') > phone= phone.gsub(/\(/,' ') > phone= phone.gsub(/\)/,'-') You could make you life easier by - using String#gsub! - combining regexps which have the same replacement > puts phone > > > # Writing data into a csv file > FasterCSV.open("test.csv", "w") do |csv| >   csv << [bname,phone] > > end > And what exactly was your question? Regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/