我正在尝试通过代理从watir webdriver访问web。可以是HTTP或SOCKS
到目前为止,这是我的代码。我找到了样本(最后3行),但它给了我错误:
irb
require "watir-webdriver"
browser = Watir::Browser.new :chrome
switches = '--proxy-server=88.12.44.205:3128'
browser = Watir::Browser.new :chrome, :switches => switches
browser.goto "http://ipaddresslocation.org"
已启动ChromeDriver port = 53928版本= 18.0.1022.0 log = C:\ Users \ Raimis \ chromedriver.log ArgumentError :: args必须是 字符串数组 来自C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/s elenium / webdriver / chrome / bridge.rb:71:in
create_capabilities' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/s elenium/webdriver/chrome/bridge.rb:20:in
initialize' 来自C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/s elenium / webdriver / common / driver.rb:37:innew' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/s elenium/webdriver/common/driver.rb:37:in
for' 来自C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/s elenium / webdriver.rb:61:infor' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.5.3/lib/watir -webdriver/browser.rb:35:in
initialize' from(irb):6:innew' from (irb):6 from C:/Ruby193/bin/irb:12:in
'
这一行给了我错误
browser = Watir::Browser.new :chrome, :switches => switches
有关如何解决此错误的任何提示?
编辑:
这是最终的代码,对我有用:
irb
require "watir-webdriver"
browser = Watir::Browser.new :chrome, :switches => ['--proxy-server=88.12.44.205:3128']
browser.goto "http://ipaddresslocation.org"
答案 0 :(得分:5)
问题在于'切换'价值必须是一个'字符串数组'而不只是一个字符串。
以下内容应该有效:
browser = Watir::Browser.new :chrome, :switches => ['--proxy-server=88.12.44.205:3128']
或者,如果您有很多选项要设置,那么您可以这样做:
switches = Array.new
switches << '--proxy-server=88.12.44.205:3128'
#Add other switches values to the array
browser = Watir::Browser.new :chrome, :switches => switches
答案 1 :(得分:2)
如果要使用SOCKS5代理,可以使用以下开关
--proxy-server=socks5://localhost:PORT
答案 2 :(得分:2)
从chromedriver 2(检查$ chromedriver -v)开始,我设法将命令行参数传递给chrome / chromium。例如,要将tor用作代理:
args = ['--start-maximized', '--proxy-server=socks://127.0.0.1:9050']
browser = Watir::Browser.new :chrome, :args => args
检查任何Chrome帮助文档中的其他可能参数,例如