Module: GetProxyList
- Included in:
- Debug, FromProxyCn
- Defined in:
- lib/get_proxy_list.rb,
lib/get_proxy_list/base.rb,
lib/get_proxy_list/from_proxycn.rb,
lib/get_proxy_list/from_proxy_cn.rb
Defined Under Namespace
Classes: Base, FromProxyCn, FromProxycn
Class Method Summary
collapse
Class Method Details
.get_list(limit, page) ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/get_proxy_list.rb', line 6
def self.get_list(limit,page)
fromProxyCn = FromProxyCn.new()
base = Base.new()
proxylist = fromProxyCn.get_proxylist(page)
proxylist = base.get_proxy_in_time_limit(limit,proxylist)
return proxylist
end
|
.get_proxy_in_time_limt(limit, proxylist) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/get_proxy_list.rb', line 14
def self.get_proxy_in_time_limt(limit,proxylist)
limit_list = []
proxylist.each do |proxy|
url = proxy
time_start = Time.now.to_i
begin
timeout(limit+1) do
doc = Nokogiri::HTML(open("http://www.baidu.com",:proxy=> url))
x = doc.css("em")
end
time_end = Time.now.to_i
time_use = time_end - time_start
p "url use_time:#{time_use}"
rescue Exception =>e
case e
when Errno::ETIMEDOUT
p "Use #{url} timeout"
when Timeout::Error
p "Use #{url} timeout"
when Errno::ECONNREFUSED
p "Use #{url} Error connection"
else
p "Use #{url} Error:#{e.to_s}"
end
time_use = -1
end
if(time_use > 0 &&time_use < limit)
limit_list << url
end
end
limit_list
end
|