parsing - check proxy and get timout with ruby-on-rails -
i have ruby on rails 4. how can check proxy , information abot proxy (timeout , etc.), if work?
i parse page nokoriri through proxy.
page = nokogiri::html(open("http://bagche.ru/home/radio_streem/", :proxy => "http://213.135.96.35:3129", :read_timeout=>10))
gem install curb
require 'net/http' require 'net/ping' require 'curb' def proxy_check @proxies = proxy.all url = "ya.ru" @proxies.each |p| proxy = net::ping::tcp.new(p.proxy_address, p.proxy_port.to_i) if proxy.ping? @resp = curl::easy.new(url) { |easy| easy.proxy_url = p.proxy_address easy.proxy_port=p.proxy_port.to_i # easy.timeout=90 # easy.connect_timeout=30 easy.follow_location = true easy.proxy_tunnel = true } begin @resp.perform @resp.response_code rescue puts "curl_get -e- fail "+p.proxy_address if @resp.response_code == 200 p.proxy_status = 1 p.proxy_timeout = @resp.total_time else p.proxy_status = 0 puts "curl_get fail "+p.proxy_address end end else p.proxy_status = 0 puts "ping fail "+p.proxy_address end p.save end end
returned 200 if availabil.
Comments
Post a Comment