I'm trying to figure out how to route my requests through an HTTP proxy.
I'm initializing webdriver like this:
user_agent = 'my user agent 1.0'
DesiredCapabilities.PHANTOMJS['phantomjs.page.settings.userAgent'] = user_agent
driver = webdriver.PhantomJS()
I've gone through the docs and the source and can't seem to find a way to use a proxy server with phantomjs for through webdriver.
Any suggestions?
I dug a little and I found that the functionality is there, but it is not exposed. So it requires a handy monkey wrench to patch it up. Here is the solution that works for me until this functionality is fully exposed in the webdriver call.
EDIT: it seems the service_args are now exposed, you no longer need to monkey patch selenium to use the proxy ... see @alex-czech answer for how to use.
Also useful are the following settings, especially when using a proxy that may take a very long time to load.
Below is the example of how to set proxy for PhantomJs in Python. You may change proxy type: socks5/http.
The following is how to do the same with the Webdriver in Ruby. I couldn't find this anywhere online until I dug into the source code:
I ended up needing to pass the credentials in both the service_args & as a proxy-auth header. I don't believe phantomjs passes the proxy auth onwards correctly.
Where proxy's structure is defined as
http://username:password@domain:port
I'd hazard a guess that the first auth-parameters aren't passed as a header to the proxy, so you need to do both manually.