Irb output

hi,

i have a ruby/watir script that i evoke from irb containing the
following lines:

ie_attach = Watir::IE.attach(:url, /text/)
ie_attach.show_links

this will attach to an open browser containing a webpage with ‘text’ in
the url and then display all the html objects in that page.

can anyone advise on how i can redirect this output in the irb window
into a file

thanks.

newyorkdolluk wrote:

hi,

i have a ruby/watir script that i evoke from irb containing the
following lines:

ie_attach = Watir::IE.attach(:url, /text/)
ie_attach.show_links

this will attach to an open browser containing a webpage with ‘text’ in
the url and then display all the html objects in that page.

can anyone advise on how i can redirect this output in the irb window
into a file

thanks.

require ‘watir’
include Watir

ie = IE.attach(:url, “http://www.ruby-forum.com/topic/76597#new”)
file = File.new(“links.txt”,“w+”)

ie.links.each {|link|
file.puts("#{link.innerText} - #{link.href}") unless
link.innerText.empty?
}

file.close()

Portion of output (some word wrapping may occur)

Ruby - http://www.ruby-forum.com/forum/4
Forum List - http://www.ruby-forum.com/
New Topic - http://www.ruby-forum.com/topic/new?forum_id=4
Search - http://www.ruby-forum.com/search
User settings - http://www.ruby-forum.com/user/edit
User List - http://www.ruby-forum.com/user/list
Log Out [pkspence] - http://www.ruby-forum.com/user/logout
irb output - http://www.ruby-forum.com/topic/76597#120103
Reply with quote -
http://www.ruby-forum.com/topic/76597?reply_to=120103#postform
Enable email notification -
http://www.ruby-forum.com/topic/subscribe/76597

Thats great thanks. Can this be modified so that we pull out only the
index names (first column of output - looks like an integer) for those
lines that have the text ‘example’ say in them?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs