如何将两个参数插入 watir :: 浏览器( Browser.new() 之后的代理和用户代理)

How to insert two parameters into watir :: browser ( proxy and user-agent after Browser.new() )

我需要在浏览器中放置代理 + user.agent = Watir::Browser.new(here)

我有一个调用代理参数的代码

u_proxy = File.readlines("proxy.txt").sample
real_proxy = u_proxy
server = ProxyChainRb::Server.new
generated_proxy = server.start(real_proxy)

proxy = {
http: generated_proxy,
ssl: generated_proxy
}

browser = Watir::Browser.new(:chrome, proxy: proxy)

和调用用户代理参数的代码

driver = Webdriver::UserAgent.driver(:browser => :chrome,:agent => :random)
browser = Watir::Browser.new(driver)

它们是分开工作的,但是如何将它们组合成一个整体呢?

尝试使用 class 但我是初学者,我可能做错了什么,因为我同时打开了 3 个浏览器!

require 'watir'
require "proxifier/proxy"
require 'proxy_chain_rb'
require 'webdriver-user-agent'
driver = Webdriver::UserAgent.driver(:browser => :chrome,:agent => :random)
 
class NameClass
    def proxys
        u_proxy = File.readlines("proxy.txt").sample
        real_proxy        =   u_proxy
        server            =   ProxyChainRb::Server.new
        generated_proxy   =   server.start(real_proxy)
 
    proxy = {
        http: generated_proxy,
        ssl:  generated_proxy
     }  
        browser = Watir::Browser.new(:chrome, proxy: proxy)
    end
 
 
    def useragents
        browser = Watir::Browser.new(driver)
    end
end
 
q = NameClass.new
 
browser = Watir::Browser.new
begin q.proxys
    browser.goto("https://2ip.ru/")
    sleep(25)
end

请帮帮我

我认为 Webdriver::UserAgent 通过了它不知道的任何选项。我会尝试:

driver = Webdriver::UserAgent.driver(:browser => :chrome, :agent => :random, :proxy => proxy)
browser = Watir::Browser.new(driver)