Class: ProxyList::SiteFreeproxylists

Inherits:
Object
  • Object
show all
Defined in:
lib/proxy_list/site_freeproxylists.rb

Constant Summary collapse

@@url =
"http://www.freeproxylists.net/ja/?c=COUNTRY_CODE&pt=&pr=&a[]=0&a[]=1&a[]=2&u=0"

Instance Method Summary collapse

Constructor Details

#initialize(country_code) ⇒ SiteFreeproxylists

initialize



8
9
10
# File 'lib/proxy_list/site_freeproxylists.rb', line 8

def initialize(country_code)
  @@url.gsub!(/COUNTRY_CODE/,country_code)
end

Instance Method Details

#proxy_listsArray

get proxy lists



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/proxy_list/site_freeproxylists.rb', line 15

def proxy_lists
  session = Capybara::Session.new(:poltergeist)
  session.driver.headers = {'User-Agent' => USER_AGENTS.sample}
  session.visit(@@url)
  proxy_lists = []
  session.all(:xpath,"/html/body/div[1]/div[2]/table//tr[not(@class='Caption')]").each do |node|
    if !node.text.nil? && node.has_xpath?('td[3]')
      proxy_lists.push("#{node.find(:xpath,'td[3]').text.downcase}://#{node.find(:xpath,'td[1]').text}:#{node.find(:xpath,'td[2]').text}")
    end
  end
  Capybara.reset_sessions!
  session.driver.quit
  proxy_lists
end