# Check for active web pages with open-uri

**URL:** <https://www.ruby-forum.com/t/check-for-active-web-pages-with-open-uri/114916>\
**Category:** Ruby\
**Created:** [September 18, 2007, 7:41pm UTC](https://www.ruby-forum.com/t/check-for-active-web-pages-with-open-uri/114916 "2007-09-18T19:41:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![animate123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@animate123](https://www.ruby-forum.com/u/animate123)\
**Post date:** [September 18, 2007, 7:41pm UTC](https://www.ruby-forum.com/t/check-for-active-web-pages-with-open-uri/114916/1 "2007-09-18T19:41:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![animate123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@animate123](https://www.ruby-forum.com/u/animate123)\
**Post date:** [September 18, 2007, 7:44pm UTC](https://www.ruby-forum.com/t/check-for-active-web-pages-with-open-uri/114916/2 "2007-09-18T19:44:36Z")

</div>

Chuck D. 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?

---

<div class="post-metadata">

**Author:** ![animate123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@animate123](https://www.ruby-forum.com/u/animate123)\
**Post date:** [September 18, 2007, 10:45pm UTC](https://www.ruby-forum.com/t/check-for-active-web-pages-with-open-uri/114916/3 "2007-09-18T22:45:38Z")

</div>

Tim H. wrote:

> Chuck D. 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.

---

<div class="post-metadata">

**Author:** ![animate123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@animate123](https://www.ruby-forum.com/u/animate123)\
**Post date:** [September 18, 2007, 10:56pm UTC](https://www.ruby-forum.com/t/check-for-active-web-pages-with-open-uri/114916/4 "2007-09-18T22:56:58Z")

</div>

Chuck D. wrote:

> > > 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.
