【发布时间】:2014-07-28 22:43:40
【问题描述】:
我有 50,000 个网站的列表,我想知道他们有什么样的协议。我拥有的所有网站都有所有 names.com 或 like something.com,但没有一个有 http://google.com。我确实尝试过运行 each 并手动检查..
require 'rubygems'
require 'open-uri'
require 'io/console'
require 'open_uri_redirections'
require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
filename = "./testfile.txt"
destination = File.open("./11aa.txt", "a")
newArray = Array.new
newArray = IO.readlines(filename)
newArray.each do |url|
begin
puts "#{url}"
if open(url,:read_timeout=>2 )
destination.write "#{url}"
end
rescue => e
puts e.message
end
end
确实有效,但需要很长时间才能完成。我正在寻找更好的算法来检查。
谢谢
【问题讨论】:
-
“协议”是什么意思?用于 URL 的 IP 协议?
-
我的意思是方案“http”或“https”。我不想错过任何网站,所以我需要检查该网站是否存在。然后我需要在上面运行海葵刮刀。所以我必须事先决定。
标签: ruby-on-rails ruby open-uri