Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome Watir Webdriver-在google chrome上更改代理_Google Chrome_Webdriver_Watir_Watir Webdriver - Fatal编程技术网

Google chrome Watir Webdriver-在google chrome上更改代理

Google chrome Watir Webdriver-在google chrome上更改代理,google-chrome,webdriver,watir,watir-webdriver,Google Chrome,Webdriver,Watir,Watir Webdriver,我正在尝试通过代理从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 => sw

我正在尝试通过代理从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端口=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\u功能'
来自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:in
new'
来自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:in
for'
来自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:in
new'
来自(irb):6
来自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"

问题是“switches”值需要是一个“字符串数组”,而不仅仅是一个字符串

以下方面应起作用:

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
switches=Array.new
开关

如果要使用SOCKS5代理,可以使用以下开关

--proxy-server=socks5://localhost:PORT
从chromedriver 2开始(检查$chromedriver-v),我已经设法将命令行参数传递给chrome/chrome。例如,要使用tor作为代理:

args = ['--start-maximized', '--proxy-server=socks://127.0.0.1:9050']
browser = Watir::Browser.new :chrome, :args => args
检查任何chrome帮助文档中的其他可能参数,如


您知道如何使用类似的开关授权代理吗?换句话说,添加用户并传递参数。链接到我页面上的问题。