irb output

N

newyorkdolluk

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.
 
P

Patrick Spence

newyorkdolluk said:
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
 
N

newyorkdolluk

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?

Patrick said:
newyorkdolluk said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,630
Members
45,338
Latest member
41Pearline46

Latest Threads

Top