Module: HttpCrawler::Client
- Included in:
- Proxy::TestProxyApi::Client, Web::Baidu::Client
- Defined in:
- lib/http_crawler/client.rb
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
-
.for(web_name, *args) ⇒ Object
接收格式 web_name = “biquge_duquanben” 返回 HttpCrawler::Web::BiqugeDuquanben::Client 实例.
-
.for_module(module_name, *args) ⇒ Object
接收格式 module_name = “HttpCrawler::Web::BiqugeDuquanben” 返回 HttpCrawler::Web::BiqugeDuquanben::Client 实例.
Instance Method Summary collapse
- #auto_proxy=(value) ⇒ Object
- #header ⇒ Object
- #init_header ⇒ Object
-
#init_http ⇒ Object
初始化http参数.
-
#init_uri ⇒ Object
init_uri 如果未初始化@uri,则会报错 继承类需要实现 @uri = URI(“host”).
-
#initialize ⇒ Object
init_uri 如果未初始化@uri,则会报错 继承类需要重定义 init_uri.
- #update_header(parameter = {}) ⇒ Object
- #update_proxy(proxy = {}) ⇒ Object
-
#validation_page?(*arg) ⇒ Boolean
是否验证码界面.
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
27 28 29 |
# File 'lib/http_crawler/client.rb', line 27 def http @http end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
27 28 29 |
# File 'lib/http_crawler/client.rb', line 27 def uri @uri end |
Class Method Details
.for(web_name, *args) ⇒ Object
接收格式web_name = “biquge_duquanben” 返回 HttpCrawler::Web::BiqugeDuquanben::Client 实例
13 14 15 |
# File 'lib/http_crawler/client.rb', line 13 def for(web_name, *args) "HttpCrawler::Web::#{web_name.camelize}::Client".constantize.new(*args) end |
.for_module(module_name, *args) ⇒ Object
接收格式module_name = “HttpCrawler::Web::BiqugeDuquanben” 返回 HttpCrawler::Web::BiqugeDuquanben::Client 实例
22 23 24 |
# File 'lib/http_crawler/client.rb', line 22 def for_module(module_name, *args) "#{module_name}::Client".constantize.new(*args) end |
Instance Method Details
#auto_proxy=(value) ⇒ Object
75 76 77 78 79 |
# File 'lib/http_crawler/client.rb', line 75 def auto_proxy=(value) Rails.logger.debug "自动更新代理" @http.auto_proxy = value @http.update_proxy if (value == true && @http.proxy? == false) end |
#header ⇒ Object
59 60 61 |
# File 'lib/http_crawler/client.rb', line 59 def header @header ||= init_header end |
#init_header ⇒ Object
63 64 65 |
# File 'lib/http_crawler/client.rb', line 63 def init_header nil end |
#init_http ⇒ Object
初始化http参数
48 49 50 |
# File 'lib/http_crawler/client.rb', line 48 def init_http end |
#init_uri ⇒ Object
init_uri 如果未初始化@uri,则会报错
继承类需要实现 @uri = URI("http://host")
55 56 57 |
# File 'lib/http_crawler/client.rb', line 55 def init_uri @uri = nil end |
#initialize ⇒ Object
init_uri 如果未初始化@uri,则会报错
继承类需要重定义 init_uri
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/http_crawler/client.rb', line 33 def initialize raise "Client uri为空" unless init_uri @http = HttpCrawler::HTTP.new(uri.host, uri.port) @http.use_ssl = (uri.scheme == "https") @http.open_timeout = 5 @http.read_timeout = 5 @http.proxy_key = "#{self.class}" init_http Rails.logger.debug "proxy_key => #{@http.proxy_key}" end |
#update_header(parameter = {}) ⇒ Object
67 68 69 |
# File 'lib/http_crawler/client.rb', line 67 def update_header(parameter = {}) nil end |
#update_proxy(proxy = {}) ⇒ Object
71 72 73 |
# File 'lib/http_crawler/client.rb', line 71 def update_proxy(proxy = {}) @http.update_proxy(proxy) end |
#validation_page?(*arg) ⇒ Boolean
是否验证码界面
82 83 84 |
# File 'lib/http_crawler/client.rb', line 82 def validation_page?(*arg) false end |