On Mon, May 28, 2012 at 9:21 PM, steven gre <[email protected]> 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
> <code>
> 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
> </code>
And what exactly was your question?
Regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en