From: Axel Etzold Date: 2008-09-11T07:40:25+09:00 Subject: Re: How to check if a webpage exists -------- Original-Nachricht -------- > Datum: Thu, 11 Sep 2008 07:32:40 +0900 > Von: "Todd Benson" > An: ruby-talk@ruby-lang.org > Betreff: Re: How to check if a webpage exists > On Wed, Sep 10, 2008 at 4:38 PM, Davide Benini > wrote: > > This probably is trivial, but I have been googling for almost 2hs > > without finding a viable solution. > > Basically I have this rails app which uses hpricot to parse web pages. > > There's this line > > > > page = Hpricot( open(url)) > > > > If the url is wrong, or the server is down, obviously I get an > > exception. > > First I tried my luck with > > > > if page = Hpricot( open(url)) > > blah blah > > end > > > > but this did not work. > > > > Then I started googling like crazy for a method to check if a webpage is > > loadable. I only found this thread > > > > http://markmail.org/message/iurqf4ejbndbczqq > > > > I tried the suggested code, it does not work. > > Now, I am pretty sure there's a straightforward way of checking whether > > a webpage is loadable. > > Can you help me? > > Thanks in advance, > > Davide > > Not really an answer, but should point you in the right direction. > Also, I can't test with Hpricot right now due to gem install issues. > But, using open-uri... > > require 'open-uri'; begin; open('http://www.www.www') {} rescue '404 > error'; end > > Todd Dear Davide, I was just about to suggest the same thing. It works on my Ubuntu machine. Best regards, Axel -- Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten Browser-Versionen downloaden: http://www.gmx.net/de/go/browser