问题
I'm trying to configure a proxy with PhantomJS 1.9.1 in a ruby (1.8.7) script for selenium webdriver (2.25).
I saw a few examples with Firefox, and I successfully did it with this browser. I used this code :
profile = Selenium::WebDriver::Firefox::Profile.new
profile.proxy = Selenium::WebDriver::Proxy.new :ssl => 'chronos.landebitel.local:3128'
$browser = Watir::Browser.new :firefox, :profile => profile
But I can't find any examples for phantomjs. I searched and tried many solutions, but none works.
Can someone can give me an example to help me?
回答1:
Try:
Watir::Browser.new( :phantomjs,
args: '--proxy=localhost:8181'
)
回答2:
In addition to passing in a proxy to phantomjs you can also pass a username and password if the proxy requires authentication. Simply pass desired options in as a string array.
It is worth noting phantomjs support proxy authentication in this way and chromedriver does not (as of July 2013 anyway); it requires you enter the authentication into an interactive UI.
switches = ['--proxy=69.106.88.7:60199', '--proxy-auth=username:password123']
browser = Watir::Browser.new :phantomjs, :args => switches
回答3:
After years of searchings (really)
args = ['--ssl-protocol=tlsv1', "--proxy=ip:port", '--proxy-auth=username:password']
capabilities = Selenium::WebDriver::Remote::Capabilities.phantomjs("phantomjs.page.settings.userAgent" => "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36")
driver = Selenium::WebDriver.for :phantomjs, :desired_capabilities => capabilities, :args => args
@browser = ::Watir::Browser.new driver
回答4:
If you see this warning WARN Selenium [DEPRECATION] :args is deprecated. Pass switches using driver_opts
, you are still in the old version. The args: proxy_arguments
is deprecated in the new versions.
This is what you need
Watir::Browser.new :phantomjs, driver_opts: { args: proxy_arguments }
回答5:
thanks for the answers. I just back from holidays and my problems is now solve.
I launch PhantomJS with this options :
phantomjs --webdriver=777 --proxy=serveur_proxy:8080 --proxy-auth=user:password --proxy-type=http
in my terminal and this line :
$browser = Watir::Browser.new(:remote, :url => "http://localhost:777")
in my script and it's work
来源:https://stackoverflow.com/questions/17348966/using-a-proxy-with-phantomjs-in-selenium-webdriver