How to check if a webpage exists

D

Davide Benini

I extended the format, so this should work:

Hi Micheal, with the HOST part added ti the request it works better, now
I get to sort positive/negative responses.
I still get false positives, because my ISP has decided to issue a
redirect to his own error page in case of missing pages, but as I said I
am going to catch these cases later, when I parse the code with hpricot.
As a matter of fact, I don't think the response is enough to see if the
page loaded correctly; many pages might work with a redirect, if ISPs
decide to give a redirect also for wrong pages, well, I don't think
there's any chance to tell the difference.
Thanks for your help,
Davide
 
B

Bernard Kenik

Davide said:
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'
begin
open "www.does.not.exist.sdadasdas.com", :proxy=>true
p "i'm ok" #<-- ok codes here
rescue => e
p "sorry can't do"
p "error is: #{e}"
end

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?
Davide

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
/usr/local/bin/ruby
renard$


irb(main):001:0> require 'open-uri'
=> true
irb(main):002:0> begin
irb(main):003:1* open "www.does.not.exist.sdadasdas.com", :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
irb(main):009:0>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top