0

I am trying to change cities by setting the proxy using Selenium in Python:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

proxy = '198.49.68.80:80'

options = Options()
options.add_argument('--proxy-server=%s' % proxy)
driver = webdriver.Chrome()
driver.get("https://www.iplocation.net/")

However, the webpage is still displaying my home town. I have taken proxies from this free proxy list.

I have tried adding this before driver.get():

driver.delete_all_cookies()

And also adding the following options:

options.add_argument('–ignore-ssl-errors=yes')
options.add_argument('–ignore-certificate-errors')

Any ideas much appreciated.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

2

Once you add the argument:

options.add_argument('--proxy-server=%s' % proxy)

You need to pass the options object as an argument while initiating the ChromeDriver / combo as follows:

  • Using :

    driver = webdriver.Chrome(options=options)
    
  • Using :

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.chrome.service import Service
    
    options = Options()
    options.add_argument('--proxy-server=%s' % proxy)
    s = Service('C:\\BrowserDrivers\\chromedriver.exe')
    driver = webdriver.Chrome(service=s, options=options)
    driver.get('https://www.iplocation.net/')
    
  • Observation: Using a free Proxy from the Free Proxy List being located in APAC region I was identified at New Mexico

Mexico

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you for your thourough answer. Unfortunately I realised that when making my minimal example, I missed out the `options=options` argument. I have been using Docker where this shows the same problem despite including the `options=options`. I will post another question after some more research. – Will Powell Feb 23 '23 at 12:54