查看文章 |
用简单的ruby脚本检查链接是否有效
2009-04-28 00:00
用程序生成了一批映射的链接,不知道是否目标地址是否是存在,手工检查简直浪费时间。暂且用ruby脚本写个URL的检查程序 require 'net/http' require 'uri' t = Array.new t<<"/flights/chengdu/,成都酒店图片,http://tupian.hotel.qunar.com/chengdu/" #需要检查的链接数据 for line in t cs = line.split(',') url = URI.parse(cs[2]) req = Net::HTTP::Get.new(url.path) res = Net::HTTP.start(url.host, url.port) {|http| http.request(req) } if res.code !='404' puts line #如果不是404则直接输入连接 end end |
最近读者: