Module: UserAgent
- Defined in:
- lib/webdriver-user-agent-randomizer.rb
Class Method Summary collapse
Class Method Details
.driver(options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/webdriver-user-agent-randomizer.rb', line 9 def self.driver ={} [:browser] ||= :firefox user_agent = ua_pool[Random.rand(ua_pool.size)] case [:browser] when :firefox [:profile] ||= Selenium::WebDriver::Firefox::Profile.new [:profile]['general.useragent.override'] = user_agent when :chrome [:switches] ||= [] [:switches] << "--user-agent=#{user_agent}" else raise "WebDriver UserAgent currently only supports :firefox and :chrome." end driver = Selenium::WebDriver.for [:browser], .except(:browser) driver end |
.ua_pool ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/webdriver-user-agent-randomizer.rb', line 28 def self.ua_pool @ua_pool = [] ua_file = File.open(File.(UA_FILE, __FILE__), 'r') do |f| f.readlines end ua_file.each do |ua| @ua_pool << ua end @ua_pool end |