我正在尝试为Selenium Chrome使用代理服务器,但最终我的连接没有被代理。操作系统Ubuntu 19.04。通过mitmdump启动代理服务器
我也在终端中运行了mitmdump,在终端中也运行了chrome,这是成功的
proxy_port = rand(1000..4000).to_s
args = [
'mitmdump',
'--listen-host', "127.0.0.1",
'--listen-port', proxy_port,
'--mode', "upstream:http://#{proxy.ip}:#{proxy.port}",
'-w', 'log_mitmdump.txt'
]
unless proxy.login.nil?
args << '--upstream-auth'
args << "#{proxy.login}:#{proxy.password}"
end
proxy_server = ChildProcess.build(*args)
proxy_server.start
Capybara.register_driver :selenium do |app|
caps = Selenium::WebDriver::Remote::Capabilities.chrome(
"chromeOptions" => {
"args" => [
"--headless",
"--remote-debugging-port=9200>",
"--proxy-server=http://127.0.0.1:#{proxy_port}",
"--disable-dev-shm-usage",
"--blink-settings=imagesEnabled=true",
"window-size=1440,900",
"--no-sandbox",
]
}
)
Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: caps)
end
Capybara.javascript_driver = :chrome
Capybara.configure do |config|
config.default_max_wait_time = 20 # seconds
config.default_driver = :selenium
end
session = Capybara::Session.new(:selenium)
session.visit("https://2ip.ru/")
站点已打开,但未代理。