Over a million developers have joined DZone.

Load A Web Page In Ruby And Print Information

·
Found at http://www.juretta.com/log/2006/08/13/ruby_net_http_and_open-uri/


require 'open-uri'
require 'pp'

open('http://www.juretta.com/') do |f|
  # hash with meta information
  pp  f.meta
   
  # 
  pp "Content-Type: " + f.content_type
  pp "last modified" + f.last_modified.to_s
  
  no = 1
  # print the first three lines
  f.each do |line|
    print "#{no}: #{line}"
    no += 1
    break if no > 4
  end
end

Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}