Sha256: 617010c70ff084a9d55c3925698b232ccce9ea1affe690c2200a7d281e8d0af6

Contents?: true

Size: 1.63 KB

Versions: 3

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

module ProxyFetcher
  module Providers
    # FreeProxyList provider class.
    class FreeProxyList < Base
      # Provider URL to fetch proxy list
      def provider_url
        'https://free-proxy-list.net/'
      end

      # [NOTE] Doesn't support filtering
      def load_proxy_list(_filters = {})
        doc = load_document(provider_url, {})
        doc.xpath('//table[@id="proxylisttable"]/tbody/tr')
      end

      # Converts HTML node (entry of N tags) to <code>ProxyFetcher::Proxy</code>
      # object.
      #
      # @param html_node [Object]
      #   HTML node from the <code>ProxyFetcher::Document</code> DOM model.
      #
      # @return [ProxyFetcher::Proxy]
      #   Proxy object
      #
      def to_proxy(html_node)
        ProxyFetcher::Proxy.new.tap do |proxy|
          proxy.addr = html_node.content_at('td[1]')
          proxy.port = Integer(html_node.content_at('td[2]').gsub(/^0+/, ''))
          proxy.country = html_node.content_at('td[4]')
          proxy.anonymity = html_node.content_at('td[5]')
          proxy.type = parse_type(html_node)
        end
      end

      private

      # Parses HTML node to extract proxy type.
      #
      # @param html_node [Object]
      #   HTML node from the <code>ProxyFetcher::Document</code> DOM model.
      #
      # @return [String]
      #   Proxy type
      #
      def parse_type(html_node)
        https = html_node.content_at('td[6]')
        https && https.casecmp('yes').zero? ? ProxyFetcher::Proxy::HTTPS : ProxyFetcher::Proxy::HTTP
      end
    end

    ProxyFetcher::Configuration.register_provider(:free_proxy_list, FreeProxyList)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
proxy_fetcher-0.10.2 lib/proxy_fetcher/providers/free_proxy_list.rb
proxy_fetcher-0.10.1 lib/proxy_fetcher/providers/free_proxy_list.rb
proxy_fetcher-0.10.0 lib/proxy_fetcher/providers/free_proxy_list.rb