0

i was building a code to do something in selenium i have to connect to proxy to make it work i have some resendetial proxies but when i tried them on selenium it shows an error i have tried various drivers too

i have used the following codes:

proxy_url = f"{proxy_username}:{proxy_password}@{proxy_address}:{proxy_port}"
options = Options()
options.add_argument('--proxy-server=http://%s' % proxy_url)
driver = webdriver.Chrome(options=options)
driver.get('https://idk.me')
print(driver.page_source)
time.sleep(50)
driver.quit()

when using this i get:"This site can’t be reached The web page at https://idk.me might be temporarily down or it may have moved permanently to a new web address. ERR_NO_SUPPORTED_PROXIES i also tried with firefox but the user and pass authentication keeped popping up

Shadow
  • 1
  • i have also tried: ``` proxy_url = "{}:{}@{}:{}".format(user, passs, ip, port) webdriver.DesiredCapabilities.CHROME['proxy'] = { "httpProxy": proxy_url, "ftpProxy": proxy_url, "sslProxy": proxy_url, "noProxy": None, "proxyType": "MANUAL", "class": "org.openqa.selenium.Proxy", "autodetect": False } url = 'https://www.ufficiocamerale.it/' driver = webdriver.Chrome(desired_capabilities=webdriver.DesiredCapabilities.CHROME) ``` but it shows my ip instead of proxys – Shadow Jun 06 '23 at 19:16

1 Answers1

1

If you want to use Selenium with a proxy server that has authentication, you'll need to create a Chromium extension with the correct configuration, which is detailed here: https://stackoverflow.com/a/35293284/7058266

Alternatively, you can use selenium-wire to run Selenium on a proxy server that has authentication, which is detailed here: https://stackoverflow.com/a/56276796/7058266

Another way is to run a SeleniumBase test with a command-line option that specifies a proxy server with authentication:

pytest --proxy=USERNAME:PASSWORD@IP_ADDRESS:PORT

(That option does the work of creating the Chromium extension for you.)

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48
  • hey when i tried to use the first one it seems that i cant use headless mode with extension so i cant use it when i tried selenium-wire it shows me alot of error like http 404 not found etc. i didn tunderstanf the third one mind explaining? – Shadow Jun 07 '23 at 20:25
  • See https://stackoverflow.com/a/73840130/7058266 for the new headless mode if you want to use headless mode with extensions. – Michael Mintz Jun 07 '23 at 20:29
  • i have tried using --headless=chrome but shows same – Shadow Jun 07 '23 at 20:41
  • 1
    You need ``--headless=new`` for Chrome 109 and above. – Michael Mintz Jun 07 '23 at 20:42
  • 1
    Just adding link to the [release notes](https://developer.chrome.com/articles/new-headless/) of the *new Chrome headless mode* (without which you would get empty pages!) @MichaelMintz : let me appreciate some of your finest answers now for a while... – mirekphd Jul 04 '23 at 20:16