Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Check url address

Reply
Thread Tools

Check url address

 
 
Lukáš N.
Guest
Posts: n/a
 
      05-04-2011
Hello all,

i would like to do something like define two urls, primary and
secondary. After that, check them and if primary is not available,
choose secondary url. At the end, put these to some variable for next
usage.

Thanks a lot! L.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Jess Gabriel y Galn
Guest
Posts: n/a
 
      05-04-2011
On Wed, May 4, 2011 at 9:50 AM, Luk=C3=A1=C5=A1 N. <(E-Mail Removed)> =
wrote:
> Hello all,
>
> i would like to do something like define two urls, primary and
> secondary. After that, check them and if primary is not available,
> choose secondary url. At the end, put these to some variable for next
> usage.


You can try to open the first URL and if there's any exception, use
the second one.
Something like:

ruby-1.9.1-p431 :004 > require 'open-uri'
=3D> true
ruby-1.9.1-p431 :005 > url1 =3D "http://fsdfsdfsdf.com"
=3D> "http://fsdfsdfsdf.com"
ruby-1.9.1-p431 :006 > url2 =3D "http://www.google.com"
=3D> "http://www.google.com"
ruby-1.9.1-p431 :007 > valid_url =3D begin
ruby-1.9.1-p431 :008 > open(url1)
ruby-1.9.1-p431 :009?> url1
ruby-1.9.1-p431 :010?> rescue
ruby-1.9.1-p431 :011?> url2
ruby-1.9.1-p431 :012?> end
=3D> "http://www.google.com"
ruby-1.9.1-p431 :013 > valid_url
=3D> "http://www.google.com"

Jesus.

 
Reply With Quote
 
 
 
 
Lukáš N.
Guest
Posts: n/a
 
      05-04-2011
Great, thank you so much

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to selecet check box in the data grid ?? only one check box mit ASP .Net 1 01-25-2006 06:47 PM
how to check all check boxes in repeater control kris ASP .Net 0 09-22-2005 06:29 PM
URL - substitution of a correct URL by a GUID like URL in favorites. Just D. ASP .Net Mobile 0 08-11-2004 04:26 PM
redirect URL's, return URL's, and URL Parameters Jon paugh ASP .Net 1 07-10-2004 05:29 AM
.Net Pro include Visual Source Safe or other Code Check in Check out software? Davisro ASP .Net 1 06-14-2004 03:23 PM



Advertisments