would you mind to tell me how to fix it, to make the following program
to run?
require 'rubygems'
require 'open-uri'
url="www.123.com"
open(url){|file| if url don't exists then puts "url don't exists"
else puts "url exists"}
thiks
url = URI.parse('www.123.com')
status = Net::HTTP.start(url.host, url.port) {|http|
http.head(url.path)
}
puts( /^2/ =~ status.code ? "ok" : "nok" )
Kind regards
robert
···
2010/7/20 Pen Ttt <myocean135@yahoo.cn>:
would you mind to tell me how to fix it, to make the following program
to run?
require 'rubygems'
require 'open-uri'
url="www.123.com"
open(url){|file| if url don't exists then puts "url don't exists"
else puts "url exists"}
irb(main):017:0> def getURL(u)
irb(main):018:1> begin
irb(main):019:2* x = open(u)
irb(main):020:2> rescue
irb(main):021:2> puts "url does not exist"
irb(main):022:2> end
irb(main):023:1> end
=> nil
irb(main):025:0> getURL("http://www.awqes.com")
url does not exist
=> nil
irb(main):026:0> getURL("http://www.google.com")
=> #<StringIO:0x15bd550>
irb(main):027:0>
Not the string "url does not exist" is for visual confirmation.
Though the x is returned as nil on a non-existent URL.
`
···
From: Pen Ttt <myocean135@yahoo.cn>
Reply-To: <ruby-talk@ruby-lang.org>
Newsgroups: comp.lang.ruby
Date: Tue, 20 Jul 2010 14:00:57 +0900
To: ruby-talk ML <ruby-talk@ruby-lang.org>
Subject: how to judge web exists or not with open-uri?
would you mind to tell me how to fix it, to make the following program
to run?
require 'rubygems'
require 'open-uri'
url="www.123.com"
open(url){|file| if url don't exists then puts "url don't exists"
else puts "url exists"}
thiks
--
Posted via http://www.ruby-forum.com/\.