Search code examples
pythonpython-3.xselenium-webdriverwebdriverselenium-firefoxdriver

how to use proxy in selenium 4.1


i am trying to make an automation project which will use proxy to register in a site. but i am unable to get it work.

I have tried selenium-wire for proxy authentication still it doesn't work

from seleniumwire import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
import os
import keyboard
import pyautogui
from time import sleep


user = 'jesbeqki'
pwd = '1wbt8dnqtu8w'
end = '2.56.119.93:5074'

seleniumwire_options ={
    "proxies" : {
    "https": "http://"f"{user}:{pwd}@{end}/",
    "http": "http://"f"{user}:{pwd}@{end}/",
    'verify_ssl': False
}
}
firefox_options = Options()
# firefox_options.add_argument("--headless")
driver = webdriver.Firefox(options=firefox_options, seleniumwire_options=seleniumwire_options)

driver.get('https://httpbin.org/ip')

text = driver.find_element(By.TAG_NAME, 'body').text
print(text)

it's showing my original ip.


Solution

  • You can use SeleniumBase to proxy to a site.

    pip install seleniumbase, then run this with python after filling in the proxy details:

    from seleniumbase import SB
    
    with SB(uc=True, proxy="USER:PASS@IP:PORT") as sb:
        sb.driver.get("https://whatismyip.com")
        sb.sleep(5)