1

for a long time i used the following code to create a selenium-driver for chrome:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

HOSTNAME = "109.175.226.252"
PORT = "12345"
prox = Proxy()
prox.proxy_type = ProxyType.MANUAL
prox.http_proxy = prox.ssl_proxy = f"{HOSTNAME}:{PORT}"
capabilities = webdriver.DesiredCapabilities.CHROME
prox.add_to_capabilities(capabilities)
driver = webdriver.Chrome (service=srv, options=options, desired_capabilities=capabilities)

But recently i get the following error when running the code:

Traceback (most recent call last):
  File "C:\DEV\Fiverr\ORDER\jonpetrich\collSuperATV.py", line 97, in <module>
    prox.add_to_capabilities(capabilities)
AttributeError: 'Proxy' object has no attribute 'add_to_capabilities'

How can i use my proxies with selenium?

1 Answer 1

1

You can use https://github.com/seleniumbase/SeleniumBase for it.

Set the proxy in HOST:PORT format or USER:PASS@HOST:PORT format. Eg:

from seleniumbase import Driver

driver = Driver(browser="chrome", proxy="109.175.226.252:12345")

You'll need to set a valid proxy. (The one from your example wasn't active.)

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

4 Comments

Thx a lot - but i would like to create the driver the same way i did it before (withtout using SeleniumBase)
To do proxy with authentication in regular selenium requires either creating a zipped chrome extension with the proxy config details (stackoverflow.com/a/35293284/7058266) or a selenium framework that does those things for you. But if you just want a regular proxy without auth, it's just options.add_argument('--proxy-server=IP:PORT') now.
Thx - i think this works now using the above format with USER:PASS@HOST:PORT and seleniumbase like you described it in your solution. I also found that i can use the parameters (uc= and headless= for undectectedchromebrowser and headless). But was not able to find a comprehensive overivew of all the potential parameters for the Driver-generation - maybe you also know where to find this documentaton exactly?
The full list of Driver() args can be found here: github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/…

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.