How to check if a webpage exists

Davide B. wrote:

Hi Axel,
I work on Mac Os X Leopard. Ruby works allright, I have also a number of
rails websites running locally, no problems so far.
Could you help me with the proper “script” sintax; I am sure the
rationale beyond the mechanism is correct, but I ultimately need to
integrate this script in a rails application, so I need to have it
woking in a common .rb file. As I said, tried this

require ‘open-uri’
open “”, :proxy=>true
p “i’m ok” #<-- ok codes here
rescue => e
p “sorry can’t do”
p “error is: #{e}”

Simple as it seems, it does not work, I always end up with “i’m ok”. I’m
sure it’s some stupid syntactic glitch…
Any suggestion?

I relealize that that this may not solve your problem.
This above script works fine on my Mac

renard$ ruby -v
ruby 1.8.6 (2008-08-11 patchlevel 287) [i686-darwin9.4.0]
renard$ which ruby

irb(main):001:0> require ‘open-uri’
=> true
irb(main):002:0> begin
irb(main):003:1* open “”, :proxy=>true
irb(main):004:1> p “i’m ok” #<-- ok codes here
irb(main):005:1> rescue => e
irb(main):006:1> p “sorry can’t do”
irb(main):007:1> p “error is: #{e}”
irb(main):008:1> end
“sorry can’t do”
“error is: can’t convert Hash into String”
=> nil

On Fri, Sep 12, 2008 at 12:58 AM, Davide B.
[email protected] wrote:

Anyway, for some reason the script does not work yet. Working pages
(like or, italian most popular newpaper
websites) output a 400 status, and the script fails. Moreover, if I
insert a url without a www (like for my own website,, the connection doesn’t even start.
Why is that? Do you think there’s a problem with the request format?

I extended the format, so this should work:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs