gpt4 book ai didi

google-chrome - Watir Webdriver - 在谷歌浏览器上更改代理

转载 作者:行者123 更新时间:2023-12-04 23:07:08 25 4
gpt4 key购买 nike

我正在尝试通过代理从 watir webdriver 访问网络。可以是 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"

Started ChromeDriver port=53928 version=18.0.1022.0 log=C:\Users\Raimis\chromedriver.log ArgumentError: :args must be an Array of Strings from 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' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/s elenium/webdriver/common/driver.rb:37:in new'
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' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/s elenium/webdriver.rb:61:in for'
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:in new'
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"

最佳答案

问题是“开关”值需要是一个“字符串数组”而不仅仅是一个字符串。

以下应该工作:

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

关于google-chrome - Watir Webdriver - 在谷歌浏览器上更改代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9535957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com