getting a page source into a file using ruby

0 views
Skip to first unread message

Krishna Vutukuru

unread,
Oct 4, 2007, 6:56:44 PM10/4/07
to rubyonra...@googlegroups.com
Does anybody know to get the source of a given webpage saved to a
notepad using ruby? I appreciate your help......
--
Posted via http://www.ruby-forum.com/.

Krishna Vutukuru

unread,
Oct 4, 2007, 6:59:10 PM10/4/07
to rubyonra...@googlegroups.com
Krishna Vutukuru 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 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?

Raoul

unread,
Oct 4, 2007, 7:48:48 PM10/4/07
to Ruby on Rails: Talk
Here's code taken from the help file that comes with Ruby One-Click
installer for windows:

require 'net/http'

h = Net::HTTP.new('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

Reply all
Reply to author
Forward
0 new messages