[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

check for active web pages with open-uri

Charles Pareto

9/18/2007 5:41:00 PM

I'm using openuri module to open web pages. If the pages doesn't exist I
get an error:
in `initialize': getaddrinfo: no address associated with hostname.
(SocketError)

then I get a whole bunch of other stuff. Is there a parameter to use so
that open() returns a true or false value if the page exists or not?
Basically I'm looking through a list of web addresses and I want to
store the active pages and throw away the non active pages. So if the
page doesn't exist I want to be able to move on in the script.
--
Posted via http://www.ruby-....

3 Answers

Tim Hunter

9/18/2007 5:45:00 PM

0

Chuck Dawit wrote:
> I'm using openuri module to open web pages. If the pages doesn't exist I
> get an error:
> in `initialize': getaddrinfo: no address associated with hostname.
> (SocketError)
>
> then I get a whole bunch of other stuff. Is there a parameter to use so
> that open() returns a true or false value if the page exists or not?
> Basically I'm looking through a list of web addresses and I want to
> store the active pages and throw away the non active pages. So if the
> page doesn't exist I want to be able to move on in the script.

Why not use rescue to catch the SocketError?
--
Posted via http://www.ruby-....

Charles Pareto

9/18/2007 8:46:00 PM

0

Tim Hunter wrote:
> Chuck Dawit wrote:
>> I'm using openuri module to open web pages. If the pages doesn't exist I
>> get an error:
>> in `initialize': getaddrinfo: no address associated with hostname.
>> (SocketError)
>>
>> then I get a whole bunch of other stuff. Is there a parameter to use so
>> that open() returns a true or false value if the page exists or not?
>> Basically I'm looking through a list of web addresses and I want to
>> store the active pages and throw away the non active pages. So if the
>> page doesn't exist I want to be able to move on in the script.
>
> Why not use rescue to catch the SocketError?

If I use rescue will the script return back to normal flow without
exiting? I don't want the script to exit.
--
Posted via http://www.ruby-....

Tim Hunter

9/18/2007 8:56:00 PM

0

Chuck Dawit wrote:
> Tim Hunter wrote:
>> Chuck Dawit wrote:
>>> I'm using openuri module to open web pages. If the pages doesn't exist I
>>> get an error:
>>> in `initialize': getaddrinfo: no address associated with hostname.
>>> (SocketError)
>>>
>>> then I get a whole bunch of other stuff. Is there a parameter to use so
>>> that open() returns a true or false value if the page exists or not?
>>> Basically I'm looking through a list of web addresses and I want to
>>> store the active pages and throw away the non active pages. So if the
>>> page doesn't exist I want to be able to move on in the script.
>> Why not use rescue to catch the SocketError?
>
> If I use rescue will the script return back to normal flow without
> exiting? I don't want the script to exit.

If that's what you want it to do. The idea is that your rescue block
gets control when a SocketError occurs. What happens after that is up to
you.

--
RMagick OS X Installer [http://rubyforge.org/project...]
RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?for...]
RMagick Installation FAQ [http://rmagick.rubyforge.org/instal...]