Class: FreshProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/fresh_proxy.rb,
lib/fresh_proxy/version.rb

Overview

Class to scrap proxies from incloak

Constant Summary collapse

VERSION =
'0.2.3'.freeze

Instance Method Summary collapse

Constructor Details

#initializeFreshProxy

Returns a new instance of FreshProxy.



5
6
7
# File 'lib/fresh_proxy.rb', line 5

def initialize
  @agent = Mechanize.new
end

Instance Method Details

#extract_pageObject

scrap incloak page for the proxies with maxtime = 1000ms



10
11
12
# File 'lib/fresh_proxy.rb', line 10

def extract_page
  @agent.get 'https://incloak.com/proxy-list/?maxtime=1000#list'
end

#extract_proxiesObject

get the last 64 most fresh proxies



25
26
27
28
29
30
31
32
33
# File 'lib/fresh_proxy.rb', line 25

def extract_proxies
  extract_page.search('.//table//tbody//tr').map do |row|
    {
      ip: row.search('.//td[1]').text,
      port: row.search('.//td[2]').text,
      speed: row.search('.//td[4]').text
    }
  end
end

#freshObject

get the most fresh proxy



15
16
17
18
19
20
21
22
# File 'lib/fresh_proxy.rb', line 15

def fresh
  page = extract_page
  {
    ip: page.search('.//table//tbody//tr[1]//td[1]').text,
    port: page.search('.//table//tbody//tr[1]//td[2]').text,
    speed: page.search('.//table//tbody//tr[1]//td[4]').text
  }
end