On Mon, May 28, 2012 at 9:21 PM, steven gre <lists / ruby-forum.com> 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. =A0I'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
> <code>
> require 'rubygems'
> require 'fastercsv'
> require 'nokogiri'
> require 'open-uri'
> page =3D
> Nokogiri::HTML(open("http://www.yellowpages.com/florida/auto-repair?q=3Da=
uto+repair"))
> bname =3D page.css("h3.business-name.fn.has-menu.org").text
> addy =3D page.css("span.street-address").text
> csz =3D page.css("span.city-state").text
> count =3D page.css("p.result-count").text
> count =3D count.gsub(/Results 1-30 of /,'')
> phone =3D Array.new
> phone =3D page.css("span.business-phone.phone").text
> phone=3D phone.gsub(/\n/,'')
> phone=3D phone.gsub(/ /,'')
> phone=3D phone.gsub(/\(/,' ')
> phone=3D 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|
> =A0 csv << [bname,phone]
>
> end
> </code>

And what exactly was your question?

Regards

robert


--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/