Breaking News
Home / Web / Ruby / How to retreive web page contents using Ruby?

How to retreive web page contents using Ruby?

Ruby SnippetThis script retrieves the content of url and dumps it to the output .
Example copy this script into file named : get_page.rb

#!/usr/bin/ruby
require ‘net/http’
host,port,url = ARGV
http = Net::HTTP.new(host, port)
STDERR.puts “url {#url}”
response, data = http.get(url)
puts data

Usage

ruby get_page.rb <host> <port> <url>

The url is specified as a relative path

ruby get_page.rb developerfeed.com 80 /website/about[pb_builder]

Advertisment ad adsense adlogger