0

How can you use a proxy with authentication with Watir?

From the documentation

proxy = {
  http: 'my.proxy.com:8080',
  ssl:  'my.proxy.com:8080'
}
chrome_browser  = Watir::Browser.new :chrome, proxy: proxy

My proxy is structured like ip:port:username:password and doesn't appear to be working. How can I use this proxy with Watir?

4
  • did you try ...http: 'http://username:[email protected]:8080'... Commented Aug 24, 2018 at 16:45
  • What @kiril said, and also I believe it's https not ssl Commented Aug 24, 2018 at 23:45
  • @pguardiario its def. ssl! @Kiril S. doesn't work. I'm trying this as well and have problems with it. Commented Oct 25, 2018 at 16:53
  • @TheMiniJohn my research showed it isn't possible to use proxies with watir Commented Oct 25, 2018 at 17:49

1 Answer 1

1

For posterity:

You can use https://github.com/SebastianJ/proxy-chain-rb to setup a proxy on localhost without authentication that redirects to your actual proxy.

real_proxy = "http://username:password@host:port"
server = ProxyChainRb::Server.new
generated_proxy = server.start(real_proxy)

proxy = {
  http: generated_proxy,
  ssl:  generated_proxy
}

Watir::Browser.new(:chrome, proxy: proxy)

* do your scraping *

server.stop

If running headless mode is not a requirement, you can also use an extension.

Create the zip file described in Selenium using Python: enter/provide http proxy password for firefox (obviously, with your own proxy information).

Create a .crx file from the zip. You can do this in Chrome -> Settings -> Extensions -> toggle Developer mode -> Pack extension

options = { extensions: ['path of .crx file'] }
browser = Watir::Browser.new :chrome, options: options

Do note that this will not work in headless Chrome.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.