# Downloading web pages in watir

**URL:** <https://www.ruby-forum.com/t/downloading-web-pages-in-watir/101955>\
**Category:** Ruby\
**Created:** [August 8, 2006, 9:36pm UTC](https://www.ruby-forum.com/t/downloading-web-pages-in-watir/101955 "2006-08-08T21:36:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [August 8, 2006, 9:36pm UTC](https://www.ruby-forum.com/t/downloading-web-pages-in-watir/101955/1 "2006-08-08T21:36:32Z")

</div>

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

thanks

michael

---

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [August 9, 2006, 12:37am UTC](https://www.ruby-forum.com/t/downloading-web-pages-in-watir/101955/2 "2006-08-09T00:37:04Z")

</div>

michael wrote:

> 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 \<\< ‘’  
f \<\< ie.html  
f \<\< ‘’  
}

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

---

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [August 9, 2006, 1:27am UTC](https://www.ruby-forum.com/t/downloading-web-pages-in-watir/101955/3 "2006-08-09T01:27:47Z")

</div>

thanks…

body is all I want…

okay… let’s suppose i would like to download ‘[www.yahoo.com](http://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

---

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [August 9, 2006, 1:42am UTC](https://www.ruby-forum.com/t/downloading-web-pages-in-watir/101955/4 "2006-08-09T01:42:47Z")

</div>

> Note that the Watir.ie.html method returns the document.body, which does  
> not include the opening and closing 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

tags, but the page itself might not.  
This causes trouble sometimes.
