うえのをちょっと改良
require 'nkf' require 'open-uri' url =ARGV[0] sec =ARGV[1] if url == nil then puts "usage\n>#{$0} url [interval sec.]" ; exit; end if sec ==nil then sec =10 end brs="C:\\Program Files\\Mozilla Firefox\\firefox.exe" html = NKF.nkf('-w', open(url).read) ans =[] html.split(/\n|</).map{ |data| an = /\"((http|ftp)\S+)\"/.match(data) # match,1番目。[0]で全体 if an != nil ans << an[1] print "." end } puts ans.each {|address| puts address `#{brs} #{address}` sleep sec.to_i }
linkopenall.rbで保存、実行例↓(途中でCtrl+C)
d:\ruby>linkopenall http://d.hatena.ne.jp 3 ................................................................................ ................................................................................ .. http://d.hatena.ne.jp/mobile http://www.hatena.ne.jp/ d:/ruby/linkopenall.rb:26:in `sleep': Interrupt from d:/ruby/linkopenall.rb:26 from d:/ruby/linkopenall.rb:23:in `each' from d:/ruby/linkopenall.rb:23 バッチ ジョブを終了しますか (Y/N)? y d:\ruby>