# Downloading web page as HTML accessed through WATIR

**URL:** <https://www.ruby-forum.com/t/downloading-web-page-as-html-accessed-through-watir/72825>\
**Category:** Ruby\
**Created:** [October 19, 2006, 7:05am UTC](https://www.ruby-forum.com/t/downloading-web-page-as-html-accessed-through-watir/72825 "2006-10-19T07:05:48Z")\
**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:** [October 19, 2006, 7:05am UTC](https://www.ruby-forum.com/t/downloading-web-page-as-html-accessed-through-watir/72825/1 "2006-10-19T07:05:48Z")

</div>

is there anyway to download the page accessed through WATIR as html  
page??

for instance,

require ‘watir’

ie = Watir::IE.start(“[http://www.yahoo.com](http://www.yahoo.com)”)

above codes will open [www.yahoo.com](http://www.yahoo.com)… what should we do to download  
this page as yahoo.htm??

any suggestion or hints will be deeply appreciated…

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:** [October 22, 2006, 2:21am UTC](https://www.ruby-forum.com/t/downloading-web-page-as-html-accessed-through-watir/72825/2 "2006-10-22T02:21:19Z")

</div>

ie.html is what you are looking for

aFile = File.new(“yahoo.htm” , “w”)  
aFile \<\< ie.html  
aFile.close

and if you want to view the file then

ie.goto(“yahoo.htm”)

---

<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:** [October 22, 2006, 3:20pm UTC](https://www.ruby-forum.com/t/downloading-web-page-as-html-accessed-through-watir/72825/3 "2006-10-22T15:20:45Z")

</div>

michael wrote:

> above codes will open [www.yahoo.com](http://www.yahoo.com)… what should we do to download  
> this page as yahoo.htm??
> 
> any suggestion or hints will be deeply appreciated…

If this is all you need, you might as well use Net:HTTP, or open-uri -  
this should have smaller overhead since you’re not instantiating an IE  
control.

require ‘open-uri’

open(‘[http://www.yahoo.com/](http://www.yahoo.com/)’) { |html|  
open(‘yahoo.html’, ‘w’) { |out|  
out.print(html.read)  
}  
}

David V.

---

<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:** [October 24, 2006, 1:55am UTC](https://www.ruby-forum.com/t/downloading-web-page-as-html-accessed-through-watir/72825/4 "2006-10-24T01:55:42Z")

</div>

removed\_email\_address@domain.invalid wrote:

> ie.html is what you are looking for
> 
> aFile = File.new(“yahoo.htm” , “w”)  
> aFile \<\< ie.html  
> aFile.close
> 
> and if you want to view the file then
> 
> ie.goto(“yahoo.htm”)

Be very very careful here, make sure you understand what you are doing.  
Watir does _not_ see the HTML on the page-- Watir only sees the DOM in  
Internet Explorer. If the HTML is missing a “/p\>”, for instance, Watir  
can’t see it. The #html method will _always_ yield valid HTML, because  
it it interpreting the DOM, regardless of how awful the original HTML  
may or may not be.
