0

I want to set up a proxy connection to a website using python-selenium to simulate a real user from different locations and make a bot. I am trying to work with Bright Data Residential IPs and Data Centers for rotating IP addresses. But my proxy connections is not working, either it gives an error and is not able to even open the page or the website loads up but without working proxy.

from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.proxy import *
from selenium.common.exceptions import NoSuchElementException
from fake_useragent import UserAgent
import os, sys
from selenium.webdriver.chrome.service import Service as ChromeService
from seleniumwire import webdriver

delay = 30
custom_wait_time = 5

ua = UserAgent()
host = 'HOST'
port = PORT

username = 'USERNAME'
password = 'PASSWORD'

proxy_url = f'http://{username}:{password}@{host}:{port}'


# set selenium-wire options to use the proxy
seleniumwire_options = {
    "proxy": {
        "http": proxy_url,
        "https": proxy_url
    },
}

options = webdriver.ChromeOptions()
options.add_argument(f"user-agent={ua.random}")
options.add_argument("--no-sandbox")
options.add_argument("--disable-gpu")
options.add_argument("--start-maximized")
options.add_argument('--proxy-server=%s' % proxy_url)

# initialize the Chrome driver with service, selenium-wire options, and chrome options
driver = webdriver.Chrome(
    service=Service(ChromeDriverManager().install()),
    seleniumwire_options=seleniumwire_options,
    options=options
)


webdriver.DesiredCapabilities.CHROME['acceptSslCerts']=True

# navigate to the target webpage
driver.get("https://whatismyipaddress.com/")
time.sleep(delay)
# release the resources and close the browser
driver.quit()

gives error - selenium.common.exceptions.WebDriverException: Message: unknown error: net::ERR_TUNNEL_CONNECTION_FAILED

0