使用Chromium 62.0.3168.0
我已确认在直接运行socks5
时使用了我的chrome
代理:./chrome --headless --remote-debugging-port=9222 --proxy-server=socks5://127.0.0.1:9055 http://bot.whatismyipaddress.com
但是当我尝试通过Capybara时,我收到错误:
SOCKSError::ServerFailure: general SOCKS server failure
如何通过我的袜子代理让Capybara使用headless_chrome
?
我的Chrome Capybara设置无效:
Capybara.default_driver = :headless_chromium
Capybara.register_driver :headless_chromium do |app|
Capybara::Selenium::Driver.new(app, {
browser: :chrome,
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(
"chromeOptions" => {
'binary' => "#{ENV['HOME']}/chromium/src/out/Default/chrome",
'args' => ["no-sandbox", "disable-gpu", "headless",
"proxy-server=socks5://127.0.0.1:9055"]
}
)
})
end
如果我从上面的代码中删除proxy-server
arg,:headless_chromium
驱动程序可以正常工作,但不使用socks代理。
以下是poltergeist
的Capybara设置,它成功使用了socks代理:
Capybara.default_driver = :poltergeist
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {
:phantomjs => Phantomjs.path,
:phantomjs_options => ["--proxy-type=socks5", "--proxy=127.0.0.1:9055"]
})
end