pythonselenium-webdriverproxywebdriver

How can I set socks5 proxy for selenium webdriver?


I really can’t to set socks5 proxy (http too...) for my chrome webdriver in selenium for python. I tried many different ways... But I think I do something bad.

Example 1:

self.options.add_argument('--proxy-server=http://'+proxy)

Example 2:

webdriver.DesiredCapabilities.CHROME['proxy'] = {
        "socksProxy": proxy,
        "ftpProxy": proxy,
        "sslProxy": proxy,
        "noProxy": None,
        "proxyType": "MANUAL",
        "class": "org.openqa.selenium.Proxy",
        "autodetect": False
    }

Please describe fully the working example of setting up socks5 proxy on Selenium for Python and Chrome webdriver, with an example of proxy string formats (maybe i am doing something mistakes here ...).

PS Two problems which I get:

  1. Just staying old IP address.
  2. No internet connection in chrome web driver.

Solution

  • Chrome does not allow proxies with authentication. I am not sure but after reading extensively I think so... I only have one solution currently. I am using a SOCKS5 proxy without authentication by login and password.

    options = webdriver.ChromeOptions()
    proxy = '12.12.421.125:1949'
    options.add_argument('--proxy-server=socks5://' + proxy)
    driver = webdriver.Chrome(options=options)
    

    2023 edit:

    This argument is supported, according to man chromium:

    --proxy-server=host:port
    Specify the HTTP/SOCKS4/SOCKS5 proxy server to use for requests. This overrides any environment variables or settings picked via the options dialog.