----- Original Message -----
From: “Imobach González Sosa” imodev@softhome.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Wednesday, May 26, 2004 8:55 AM
Subject: Checking that an URL exists
Hi all,
Well, I want to make a little script that checks if the URLs in my bookmarks
are OK (in other words, if they are online yet).
I’ve been hanging around with URI classes and I’ve seen clearly a function
that performs that check.
I’ve tried using open-uri.rb but, if open method fails, the script fails.
–
EuropeSwPatentFree
(o_.’ Imobach González Sosa imobachgs@softhome.net
//\c{} imobachgs@step.es a2419@dis.ulpgc.es
V__)_ imodev@softhome.net osoh en jabber.at y jabber.org
Usuario Linux #201634
Gentoo Linux con núcleo 2.6.6 sobre Intel Pentium 4
This is fine if you aren’t checking very many urls. If, however, you
are going to be doing this very many times, you should use “head”
instead, to reduce the webserver’s load (and increase your applications
response time):
resp = h.head(url, nil)
Also, many invalid urls won’t raise errors, they just return error
codes in the headers. You may want to check for that, too:
h.head “/non-existant-page.html”
=> #<Net::HTTPNotFound 404 Not Found readbody=true>
h.head “/”
=> #<Net::HTTPMovedPermanently 301 Moved Permanently readbody=true>
h.head(“/”)[‘location’]
=> “Ruby Programming Language”
h.head “/en/”
=> #<Net::HTTPOK 200 OK readbody=true>
h.head
check the class of the header: Net::HTTPOK is a good url;
Net::HTTPMovedPermanantly is what it sounds like, and you can treat it
like a hash to look up the redirected location. Net::HTTPNotFound is a
dead end.
···
On May 26, 2004, at 7:09 AM, Mohammad Khan wrote:
----- Original Message -----
From: “Imobach González Sosa” imodev@softhome.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Wednesday, May 26, 2004 8:55 AM
Subject: Checking that an URL exists
Hi all,
Well, I want to make a little script that checks if the URLs in my
bookmarks
are OK (in other words, if they are online yet).
I’ve been hanging around with URI classes and I’ve seen clearly a
function
that performs that check.
I’ve tried using open-uri.rb but, if open method fails, the script
fails.
Any ideas?
Thanks in advance.
–
EuropeSwPatentFree
(o_.’ Imobach González Sosa imobachgs@softhome.net
//\c{} imobachgs@step.es a2419@dis.ulpgc.es
V__)_ imodev@softhome.net osoh en jabber.at y jabber.org
Usuario Linux #201634
Gentoo Linux con núcleo 2.6.6 sobre Intel Pentium 4
Thanks for everyone’s response. My problem was that I needed to switch the
‘p’ and the ‘attr’ so it was:
attr =~ /#{p}/
attr is something like: “Component.behavior”
p would be something like: “behavior”
Zach
···
-----Original Message-----
From: David A. Black [mailto:dblack@wobblini.net]
Sent: Wednesday, May 26, 2004 11:17 AM
To: ruby-talk ML
Subject: Re: delete_if woes