Class: ProxiesScanner::Proxies
- Inherits:
-
Object
- Object
- ProxiesScanner::Proxies
- Defined in:
- lib/proxies-scanner/proxies.rb
Constant Summary collapse
- ALL_AREAS =
[ 'us', 'fr', 'gb', 'au', 'ca', 'it', 'es', 'hu', 'ng', 'ch', 'se', 'br', 'id', 'cn', 'fi', 'be', 'co', 'hr', 'ge', 'gr', 'ie', 'mx', 'mt', 'nl', 'pa', 'ph', 'ro', 'sc', 'tw', 'tn', 'tr', 'ua', 've' ]
Class Method Summary collapse
Class Method Details
.find_by_area(area, page = 0) ⇒ Object
12 13 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 |
# File 'lib/proxies-scanner/proxies.rb', line 12 def self.find_by_area(area, page=0) $logger.info "Proxies.extract area=#{area}, page=#{page}" proxies = [] doc = Nokogiri::HTML(open("http://www.proxylists.net/#{area.downcase}_#{page}.html")) table = doc.search('table')[1] table.css('tr').each do |tr| td1 = tr.css('td')[0] td2 = tr.css('td')[1] unless td1.nil? # extract host js = td1.text.scan(/cape\('(.*)'\)\);/)[0] unless js.nil? js1 = js[0] js2 = URI.decode(js1) # self.document.writeln(\"81.199.34.100\"); $logger.debug "Proxies.extract js2: #{js2}" ip = js2.to_s.scan(/ln\("(.*)"\);/)[0][0].to_s $logger.debug "Proxies.extract ip: #{ip}" end # extract port unless td2.nil? port = td2.text.strip.to_s.to_i || 8080 end proxies << Proxy.new(ip, port, area) unless ip.nil? end end return proxies end |
.from_file(filename) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/proxies-scanner/proxies.rb', line 45 def self.from_file(filename) proxies = [] file = nil begin file = File.open(filename, 'r+') file.each_line do |line| next if line[0] == '#' s_ip = line.split(':')[0] s_port = line.split(':')[1] s_area = line.split(':')[2] || '--' $logger.debug "From file extract s_ip: #{s_ip}" $logger.debug "From file extract s_port: #{s_port}" $logger.debug "From file extract s_area: #{s_area}" proxies << Proxy.new(s_ip.strip, s_port.strip.to_i, s_area.strip) end rescue Exception => e $logger.error "From file error: #{e.}" end file.close unless file.nil? return proxies end |