# Getting a page source into a file using ruby

**URL:** <https://www.ruby-forum.com/t/getting-a-page-source-into-a-file-using-ruby/116379>\
**Category:** Rails\
**Created:** [October 5, 2007, 12:56am UTC](https://www.ruby-forum.com/t/getting-a-page-source-into-a-file-using-ruby/116379 "2007-10-05T00:56:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![krishnakishore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/bb73d2/32.png) [@krishnakishore](https://www.ruby-forum.com/u/krishnakishore)\
**Post date:** [October 5, 2007, 12:56am UTC](https://www.ruby-forum.com/t/getting-a-page-source-into-a-file-using-ruby/116379/1 "2007-10-05T00:56:44Z")

</div>

Does anybody know to get the source of a given webpage saved to a  
notepad using ruby? I appreciate your help…

---

<div class="post-metadata">

**Author:** ![krishnakishore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/bb73d2/32.png) [@krishnakishore](https://www.ruby-forum.com/u/krishnakishore)\
**Post date:** [October 5, 2007, 12:59am UTC](https://www.ruby-forum.com/t/getting-a-page-source-into-a-file-using-ruby/116379/2 "2007-10-05T00:59:10Z")

</div>

Krishna V. wrote:

> Does anybody know to get the source of a given webpage saved to a  
> notepad using ruby? I appreciate your help…

for instance if we have [www.google.com](http://www.google.com) and would want to save the source  
of that page to a text pad is there any way we can get this done in  
ruby?

---

<div class="post-metadata">

**Author:** ![krishnakishore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/bb73d2/32.png) [@krishnakishore](https://www.ruby-forum.com/u/krishnakishore)\
**Post date:** [October 5, 2007, 1:51am UTC](https://www.ruby-forum.com/t/getting-a-page-source-into-a-file-using-ruby/116379/3 "2007-10-05T01:51:26Z")

</div>

Here’s code taken from the help file that comes with Ruby O.-Click  
installer for windows:

require ‘net/http’

h = Net::HTTP.new(‘[www.pragmaticprogrammer.com](http://www.pragmaticprogrammer.com)’, 80)  
resp, data = h.get(‘/index.html’, nil)  
if resp.message == “OK”  
puts data  
end

you have the html of the page in the data variable
