Selenium Chrome Proxy Authentication in Python
Setting chromedriver proxy with Selenium using Python
If you need to use a proxy with python and Selenium library with chromedriver you usually use the following code (Without any username and password:
This works fine unless proxy requires authentication. if the proxy requires you to log in with a username and password it will not work. In this case, you have to use more tricky solution that is explained below. By the way, if you whitelist your server IP address from the proxy provider or server it should not ask proxy credentials.
HTTP Proxy Authentication with Chromedriver in Selenium
To set up proxy authentication we will generate a special file and upload it to chromedriver dynamically using the following code below. This code configures selenium with chromedriver to use HTTP proxy that requires authentication with user/password pair.
Function get_chromedriver returns configured selenium webdriver that you can use in your application. This code is tested and works just fine.
Read more about onAuthRequired event in Chrome.
Top comments (1)
How to use with options --headless ?
If i add chrome_options.add_argument('--headless')
I see in logs, when create driver:
{WebDriverException}Message: unknown error: failed to wait for extension background page to load: chrome-extension://bebklmomgilochanmemgcdlodnpmlpho/_generated_background_page.html