proxy_fetcher 0.11.0 → 0.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -1
- data/Gemfile +4 -2
- data/Rakefile +3 -1
- data/gemfiles/nokogiri.gemfile +1 -1
- data/gemfiles/oga.gemfile +2 -2
- data/lib/proxy_fetcher.rb +42 -31
- data/lib/proxy_fetcher/client/request.rb +3 -3
- data/lib/proxy_fetcher/configuration.rb +13 -9
- data/lib/proxy_fetcher/document/node.rb +1 -1
- data/lib/proxy_fetcher/manager.rb +40 -7
- data/lib/proxy_fetcher/providers/base.rb +2 -1
- data/lib/proxy_fetcher/providers/free_proxy_list.rb +0 -21
- data/lib/proxy_fetcher/providers/free_proxy_list_socks.rb +58 -0
- data/lib/proxy_fetcher/providers/free_proxy_list_ssl.rb +1 -0
- data/lib/proxy_fetcher/providers/free_proxy_list_us.rb +54 -0
- data/lib/proxy_fetcher/providers/mtpro.rb +43 -0
- data/lib/proxy_fetcher/providers/proxypedia.rb +48 -0
- data/lib/proxy_fetcher/providers/proxyscrape_http.rb +65 -0
- data/lib/proxy_fetcher/providers/proxyscrape_socks4.rb +65 -0
- data/lib/proxy_fetcher/providers/proxyscrape_socks5.rb +65 -0
- data/lib/proxy_fetcher/providers/xroxy.rb +2 -2
- data/lib/proxy_fetcher/proxy.rb +12 -0
- data/lib/proxy_fetcher/utils/http_client.rb +25 -21
- data/lib/proxy_fetcher/utils/proxy_validator.rb +20 -8
- data/lib/proxy_fetcher/version.rb +2 -2
- data/proxy_fetcher.gemspec +6 -4
- data/spec/fixtures/proxies.txt +14 -0
- data/spec/proxy_fetcher/client/client_spec.rb +10 -5
- data/spec/proxy_fetcher/manager_spec.rb +18 -0
- data/spec/proxy_fetcher/providers/proxy_classes_spec.rb +28 -0
- metadata +15 -12
- data/lib/proxy_fetcher/providers/gather_proxy.rb +0 -50
- data/spec/proxy_fetcher/providers/free_proxy_list_spec.rb +0 -13
- data/spec/proxy_fetcher/providers/free_proxy_list_ssl_spec.rb +0 -11
- data/spec/proxy_fetcher/providers/gather_proxy_spec.rb +0 -11
- data/spec/proxy_fetcher/providers/http_tunnel_spec.rb +0 -11
- data/spec/proxy_fetcher/providers/proxy_list_spec.rb +0 -11
- data/spec/proxy_fetcher/providers/xroxy_spec.rb +0 -11
@@ -10,27 +10,39 @@ module ProxyFetcher
|
|
10
10
|
|
11
11
|
# Short variant to validate proxy.
|
12
12
|
#
|
13
|
-
# @param
|
14
|
-
# @param
|
13
|
+
# @param address [String] proxy address or IP
|
14
|
+
# @param port [String, Integer] proxy port
|
15
15
|
#
|
16
16
|
# @return [Boolean]
|
17
17
|
# true if connection to the server using proxy established, otherwise false
|
18
18
|
#
|
19
|
-
def self.connectable?(
|
20
|
-
new(
|
19
|
+
def self.connectable?(address, port)
|
20
|
+
new(address, port).connectable?
|
21
21
|
end
|
22
22
|
|
23
23
|
# Initialize new ProxyValidator instance
|
24
24
|
#
|
25
|
-
# @param
|
26
|
-
# @param
|
25
|
+
# @param address [String] Proxy address or IP
|
26
|
+
# @param port [String, Integer] Proxy port
|
27
|
+
# @param options [Hash] proxy options
|
28
|
+
# @option username [String] Proxy authentication username
|
29
|
+
# @option password [String] Proxy authentication password
|
30
|
+
# @option headers [Hash] Proxy headers
|
27
31
|
#
|
28
32
|
# @return [ProxyValidator]
|
29
33
|
#
|
30
|
-
def initialize(
|
34
|
+
def initialize(address, port, options: {})
|
31
35
|
timeout = ProxyFetcher.config.proxy_validation_timeout
|
36
|
+
proxy = [address, port.to_i]
|
32
37
|
|
33
|
-
|
38
|
+
if options[:username] && options[:password]
|
39
|
+
proxy << options[:username]
|
40
|
+
proxy << options[:password]
|
41
|
+
end
|
42
|
+
|
43
|
+
proxy << options[:headers].to_h if options[:headers]
|
44
|
+
|
45
|
+
@http = HTTP.follow.via(*proxy).timeout(connect: timeout, read: timeout)
|
34
46
|
end
|
35
47
|
|
36
48
|
# Checks if proxy is connectable (can be used to connect
|
data/proxy_fetcher.gemspec
CHANGED
@@ -8,9 +8,11 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.name = "proxy_fetcher"
|
9
9
|
gem.version = ProxyFetcher.gem_version
|
10
10
|
gem.summary = "Ruby gem for dealing with proxy lists from different providers"
|
11
|
-
gem.description =
|
12
|
-
|
13
|
-
|
11
|
+
gem.description = <<-TEXT.strip.gsub(/[\s\n]+/, " ")
|
12
|
+
This gem can help your Ruby application to make HTTP(S) requests
|
13
|
+
using proxies by fetching and validating proxy lists from
|
14
|
+
the different providers.
|
15
|
+
TEXT
|
14
16
|
gem.authors = ["Nikita Bulai"]
|
15
17
|
gem.email = "bulajnikita@gmail.com"
|
16
18
|
gem.require_paths = ["lib"]
|
@@ -24,5 +26,5 @@ Gem::Specification.new do |gem|
|
|
24
26
|
gem.add_runtime_dependency "http", ">= 3", "< 5"
|
25
27
|
|
26
28
|
gem.add_development_dependency "rake", ">= 12.0"
|
27
|
-
gem.add_development_dependency "rspec", "~> 3.
|
29
|
+
gem.add_development_dependency "rspec", "~> 3.9"
|
28
30
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
139.162.59.9:3128
|
2
|
+
176.62.187.158:56351
|
3
|
+
144.217.22.142:8080
|
4
|
+
176.55.108.21:3128
|
5
|
+
157.225.214.251:3128
|
6
|
+
202.51.49.52:48298
|
7
|
+
104.244.75.26:8080
|
8
|
+
163.172.28.20:80
|
9
|
+
187.56.191.12:3128
|
10
|
+
129.194.12.26:80
|
11
|
+
178.128.39.39:8080
|
12
|
+
181.30.28.15:8080
|
13
|
+
51.181.96.185:8080
|
14
|
+
148.134.10.13
|
@@ -3,6 +3,11 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
require "json"
|
5
5
|
|
6
|
+
begin
|
7
|
+
require "webrick"
|
8
|
+
rescue LoadError
|
9
|
+
# nop
|
10
|
+
end
|
6
11
|
require "evil-proxy"
|
7
12
|
require "evil-proxy/async"
|
8
13
|
|
@@ -118,15 +123,15 @@ describe ProxyFetcher::Client do
|
|
118
123
|
end
|
119
124
|
end
|
120
125
|
|
121
|
-
|
126
|
+
context "retries" do
|
122
127
|
it "raises an error when reaches max retries limit" do
|
123
128
|
allow(ProxyFetcher::Client::Request).to receive(:execute).and_raise(StandardError)
|
124
129
|
|
125
|
-
expect { ProxyFetcher::Client.get("http://httpbin.org") }
|
130
|
+
expect { ProxyFetcher::Client.get("http://httpbin.org", options: { max_retries: 10 }) }
|
126
131
|
.to raise_error(ProxyFetcher::Exceptions::MaximumRetriesReached)
|
127
132
|
end
|
128
133
|
|
129
|
-
|
134
|
+
xit "raises an error when http request returns an error" do
|
130
135
|
allow_any_instance_of(HTTP::Client).to receive(:get).and_return(StandardError.new)
|
131
136
|
|
132
137
|
expect { ProxyFetcher::Client.get("http://httpbin.org") }
|
@@ -134,14 +139,14 @@ describe ProxyFetcher::Client do
|
|
134
139
|
end
|
135
140
|
|
136
141
|
it "refreshes proxy lists if no proxy found" do
|
137
|
-
ProxyFetcher::
|
142
|
+
allow(ProxyFetcher::Manager.new).to receive(:proxies).and_return([])
|
138
143
|
|
139
144
|
expect { ProxyFetcher::Client.get("http://httpbin.org") }
|
140
145
|
.not_to raise_error
|
141
146
|
end
|
142
147
|
end
|
143
148
|
|
144
|
-
|
149
|
+
xcontext "redirects" do
|
145
150
|
it "follows redirect when present" do
|
146
151
|
content = ProxyFetcher::Client.get("http://httpbin.org/absolute-redirect/2")
|
147
152
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe ProxyFetcher::Manager do
|
6
|
+
it "can initialize with a proxies from file(s)" do
|
7
|
+
manager = described_class.new(refresh: false, file: "spec/fixtures/proxies.txt")
|
8
|
+
|
9
|
+
expect(manager.proxies.size).to be(14)
|
10
|
+
|
11
|
+
manager = described_class.new(
|
12
|
+
refresh: false,
|
13
|
+
file: ["spec/fixtures/proxies.txt", "spec/fixtures/proxies.txt"]
|
14
|
+
)
|
15
|
+
|
16
|
+
expect(manager.proxies.size).to be(14)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe "Proxy classes" do
|
6
|
+
[
|
7
|
+
[:free_proxy_list, "FreeProxyList"],
|
8
|
+
[:free_proxy_list_socks, "FreeProxyListSocks"],
|
9
|
+
[:free_proxy_list_ssl, "FreeProxyListSSL"],
|
10
|
+
[:free_proxy_list_us, "FreeProxyListUS"],
|
11
|
+
[:http_tunnel, "HTTPTunnel"],
|
12
|
+
[:mtpro, "MTPro"],
|
13
|
+
[:proxy_list, "ProxyList"],
|
14
|
+
[:proxypedia, "Proxypedia"],
|
15
|
+
[:proxyscrape_http, "ProxyscrapeHTTP"],
|
16
|
+
[:proxyscrape_socks4, "ProxyscrapeSOCKS4"],
|
17
|
+
[:proxyscrape_socks5, "ProxyscrapeSOCKS5"],
|
18
|
+
[:xroxy, "XRoxy"]
|
19
|
+
].each do |(provider_name, provider_klass)|
|
20
|
+
describe Object.const_get("ProxyFetcher::Providers::#{provider_klass}") do
|
21
|
+
before :all do
|
22
|
+
ProxyFetcher.config.provider = provider_name
|
23
|
+
end
|
24
|
+
|
25
|
+
it_behaves_like "a manager"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proxy_fetcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Bulai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -50,14 +50,14 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '3.
|
53
|
+
version: '3.9'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '3.
|
60
|
+
version: '3.9'
|
61
61
|
description: This gem can help your Ruby application to make HTTP(S) requests using
|
62
62
|
proxies by fetching and validating proxy lists from the different providers.
|
63
63
|
email: bulajnikita@gmail.com
|
@@ -94,10 +94,16 @@ files:
|
|
94
94
|
- lib/proxy_fetcher/null_logger.rb
|
95
95
|
- lib/proxy_fetcher/providers/base.rb
|
96
96
|
- lib/proxy_fetcher/providers/free_proxy_list.rb
|
97
|
+
- lib/proxy_fetcher/providers/free_proxy_list_socks.rb
|
97
98
|
- lib/proxy_fetcher/providers/free_proxy_list_ssl.rb
|
98
|
-
- lib/proxy_fetcher/providers/
|
99
|
+
- lib/proxy_fetcher/providers/free_proxy_list_us.rb
|
99
100
|
- lib/proxy_fetcher/providers/http_tunnel.rb
|
101
|
+
- lib/proxy_fetcher/providers/mtpro.rb
|
100
102
|
- lib/proxy_fetcher/providers/proxy_list.rb
|
103
|
+
- lib/proxy_fetcher/providers/proxypedia.rb
|
104
|
+
- lib/proxy_fetcher/providers/proxyscrape_http.rb
|
105
|
+
- lib/proxy_fetcher/providers/proxyscrape_socks4.rb
|
106
|
+
- lib/proxy_fetcher/providers/proxyscrape_socks5.rb
|
101
107
|
- lib/proxy_fetcher/providers/xroxy.rb
|
102
108
|
- lib/proxy_fetcher/proxy.rb
|
103
109
|
- lib/proxy_fetcher/utils/http_client.rb
|
@@ -105,18 +111,15 @@ files:
|
|
105
111
|
- lib/proxy_fetcher/utils/proxy_validator.rb
|
106
112
|
- lib/proxy_fetcher/version.rb
|
107
113
|
- proxy_fetcher.gemspec
|
114
|
+
- spec/fixtures/proxies.txt
|
108
115
|
- spec/proxy_fetcher/client/client_spec.rb
|
109
116
|
- spec/proxy_fetcher/configuration_spec.rb
|
110
117
|
- spec/proxy_fetcher/document/adapters_spec.rb
|
111
118
|
- spec/proxy_fetcher/document/node_spec.rb
|
119
|
+
- spec/proxy_fetcher/manager_spec.rb
|
112
120
|
- spec/proxy_fetcher/providers/base_spec.rb
|
113
|
-
- spec/proxy_fetcher/providers/free_proxy_list_spec.rb
|
114
|
-
- spec/proxy_fetcher/providers/free_proxy_list_ssl_spec.rb
|
115
|
-
- spec/proxy_fetcher/providers/gather_proxy_spec.rb
|
116
|
-
- spec/proxy_fetcher/providers/http_tunnel_spec.rb
|
117
121
|
- spec/proxy_fetcher/providers/multiple_providers_spec.rb
|
118
|
-
- spec/proxy_fetcher/providers/
|
119
|
-
- spec/proxy_fetcher/providers/xroxy_spec.rb
|
122
|
+
- spec/proxy_fetcher/providers/proxy_classes_spec.rb
|
120
123
|
- spec/proxy_fetcher/proxy_spec.rb
|
121
124
|
- spec/proxy_fetcher/version_spec.rb
|
122
125
|
- spec/spec_helper.rb
|
@@ -140,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
143
|
- !ruby/object:Gem::Version
|
141
144
|
version: '0'
|
142
145
|
requirements: []
|
143
|
-
rubygems_version: 3.
|
146
|
+
rubygems_version: 3.1.2
|
144
147
|
signing_key:
|
145
148
|
specification_version: 4
|
146
149
|
summary: Ruby gem for dealing with proxy lists from different providers
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "json"
|
4
|
-
|
5
|
-
module ProxyFetcher
|
6
|
-
module Providers
|
7
|
-
# GatherProxy provider class.
|
8
|
-
class GatherProxy < Base
|
9
|
-
# Provider URL to fetch proxy list
|
10
|
-
def provider_url
|
11
|
-
"http://www.gatherproxy.com/"
|
12
|
-
end
|
13
|
-
|
14
|
-
def xpath
|
15
|
-
'//div[@class="proxy-list"]/table/script'
|
16
|
-
end
|
17
|
-
|
18
|
-
# Converts HTML node (entry of N tags) to <code>ProxyFetcher::Proxy</code>
|
19
|
-
# object.
|
20
|
-
#
|
21
|
-
# @param html_node [Object]
|
22
|
-
# HTML node from the <code>ProxyFetcher::Document</code> DOM model.
|
23
|
-
#
|
24
|
-
# @return [ProxyFetcher::Proxy]
|
25
|
-
# Proxy object
|
26
|
-
#
|
27
|
-
def to_proxy(html_node)
|
28
|
-
json = parse_json(html_node)
|
29
|
-
|
30
|
-
ProxyFetcher::Proxy.new.tap do |proxy|
|
31
|
-
proxy.addr = json["PROXY_IP"]
|
32
|
-
proxy.port = json["PROXY_PORT"].to_i(16)
|
33
|
-
proxy.anonymity = json["PROXY_TYPE"]
|
34
|
-
proxy.country = json["PROXY_COUNTRY"]
|
35
|
-
proxy.response_time = json["PROXY_TIME"].to_i
|
36
|
-
proxy.type = ProxyFetcher::Proxy::HTTP
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def parse_json(html_node)
|
43
|
-
javascript = html_node.content[/{.+}/im]
|
44
|
-
JSON.parse(javascript)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
ProxyFetcher::Configuration.register_provider(:gather_proxy, GatherProxy)
|
49
|
-
end
|
50
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe ProxyFetcher::Providers::FreeProxyList do
|
6
|
-
before :all do
|
7
|
-
ProxyFetcher.configure do |config|
|
8
|
-
config.provider = :free_proxy_list
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
it_behaves_like "a manager"
|
13
|
-
end
|