downloading web pages in watir

M

michael

could anybody tell me how to download web pages accessed through
watir??

thanks

michael
 
B

Brian Cowdery

michael said:
could anybody tell me how to download web pages accessed through
watir??

thanks

michael

While there isn't any methods in Watir to directly download a webpage to
a file, you can get the HTML content yourself and do your own file
writing.

for example;

ie = Watir::IE.new
ie.goto('www.google.ca')

File.open('google.html', "wb") { |f|
f << '<html>'
f << ie.html
f << '</html>'
}

Note that the Watir.ie.html method returns the document.body, which does
not include the opening and closing <html> tags - so you'll need to
include them in the file writing block.
 
M

michael

thanks..


body is all I want..

okay.. let's suppose i would like to download 'www.yahoo.com', and save
it as c:\yahoo\yahoo.htm

would you show me how I can realize this in ruby, watir??

thank you so much..


michael
 
C

Chris McMahon

Note that the Watir.ie.html method returns the document.body, which does
not include the opening and closing <html> tags - so you'll need to
include them in the file writing block.

Also note that Watir does *not* return the actual HTML. It returns the
DOM, represented as HTML. As an example, HTML generated from Watir's
"ie.html:" always has closed <p> tags, but the page itself might not.
This causes trouble sometimes.
 

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,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top