Thursday, March 15, 2007

Using Net::https with Hpricot to parse html

My rails app that accessed sites to extract images from web pages started throwing this error (OpenSSL::SSL::SSLError). I was using open-uri to fetch pages.

I changed my code to use Net::https to fetch pages over SSL. Here is sample code to access a web page and print it contents to terminal over SSL.

require 'rubygems'
require 'hpricot'
require 'uri'
require 'net/https'

url = ""

url1 = URI.parse(url)

http =, url1.port)
http.use_ssl = true

req =

res = http.start do |http|

puts res.body

No comments: