Some Browser::Options work
This commit is contained in:
@@ -12,6 +12,7 @@ class Browser
|
||||
|
||||
attr_reader :hydra, :config_file
|
||||
|
||||
# @param [ Hash ] options
|
||||
def initialize(options = {})
|
||||
@config_file = options[:config_file] || CONF_DIR + '/browser.conf.json'
|
||||
@cache_dir = CACHE_DIR + '/browser'
|
||||
@@ -56,10 +57,12 @@ class Browser
|
||||
data = JSON.parse(File.read(@config_file))
|
||||
end
|
||||
|
||||
ACCESSOR_OPTIONS.each do |option|
|
||||
Options::OPTIONS.each do |option|
|
||||
option_name = option.to_s
|
||||
|
||||
self.send(:"#{option_name}=", data[option_name])
|
||||
if data[option_name]
|
||||
self.send(:"#{option_name}=", data[option_name])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class Browser
|
||||
# @return [ void ]
|
||||
def basic_auth=(auth)
|
||||
if auth.index(':')
|
||||
@basic_auth = "Basic #{Base64.encode64(basic_auth.chomp)}"
|
||||
@basic_auth = "Basic #{Base64.encode64(auth.chomp)}"
|
||||
elsif auth =~ /\ABasic .*\z/
|
||||
@basic_auth = auth.chomp
|
||||
else
|
||||
@@ -44,19 +44,6 @@ class Browser
|
||||
@max_threads || 1
|
||||
end
|
||||
|
||||
# @return [ String ] The user agent, according to the user_agent_mode
|
||||
def user_agent
|
||||
case @user_agent_mode
|
||||
when 'semi-static'
|
||||
unless @user_agent
|
||||
@user_agent = @available_user_agents.sample
|
||||
end
|
||||
when 'random'
|
||||
@user_agent = @available_user_agents.sample
|
||||
end
|
||||
@user_agent
|
||||
end
|
||||
|
||||
# Sets the user_agent_mode, which can be one of the following:
|
||||
# static: The UA is defined by the user, and will be the same in each requests
|
||||
# semi-static: The UA is randomly chosen at the first request, and will not change
|
||||
@@ -78,6 +65,19 @@ class Browser
|
||||
end
|
||||
end
|
||||
|
||||
# @return [ String ] The user agent, according to the user_agent_mode
|
||||
def user_agent
|
||||
case @user_agent_mode
|
||||
when 'semi-static'
|
||||
unless @user_agent
|
||||
@user_agent = @available_user_agents.sample
|
||||
end
|
||||
when 'random'
|
||||
@user_agent = @available_user_agents.sample
|
||||
end
|
||||
@user_agent
|
||||
end
|
||||
|
||||
# Sets the proxy
|
||||
# Accepted format:
|
||||
# host:post
|
||||
|
||||
@@ -107,3 +107,8 @@ def xml(file)
|
||||
config.noblanks
|
||||
end
|
||||
end
|
||||
|
||||
def redefine_constant(constant, value)
|
||||
Object.send(:remove_const, constant)
|
||||
Object.const_set(constant, value)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user