Sha256: fb813438fac2c94698a7037d42fc6a7da930a9ab6e78de3f34c9b54b567d9dcc

Contents?: true

Size: 1.56 KB

Versions: 3

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

module ProxyFetcher
  module Providers
    # FreeProxyListSSL provider class.
    class FreeProxyListSSL < Base
      # Provider URL to fetch proxy list
      def provider_url
        'https://www.sslproxies.org/'
      end

      # Fetches HTML content by sending HTTP request to the provider URL and
      # parses the document (built as abstract <code>ProxyFetcher::Document</code>)
      # to return all the proxy entries (HTML nodes).
      #
      # @return [Array<ProxyFetcher::Document::Node>]
      #   Collection of extracted HTML nodes with full proxy info
      #
      # [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 = ProxyFetcher::Proxy::HTTPS
        end
      end
    end

    ProxyFetcher::Configuration.register_provider(:free_proxy_list_ssl, FreeProxyListSSL)
  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_ssl.rb
proxy_fetcher-0.10.1 lib/proxy_fetcher/providers/free_proxy_list_ssl.rb
proxy_fetcher-0.10.0 lib/proxy_fetcher/providers/free_proxy_list_ssl.rb