Home > Net >  Why is the proxy not changed in Selenium Python?
Why is the proxy not changed in Selenium Python?

Time:10-06

I wrote a python code and in this python code I feel that my proxy does not change

My code:

from selenium import webdriver
from time import sleep


#input proxy list
print("=======================================")
proxy = input("*\n-- please enter PROXY LIST: ")
print("*\n=======================================\n\n\n\n")

#open file list proxy
file_proxy = open(proxy,"r")

#loop proxy
for proxy in file_proxy:
    
    #set proxy
    PROXY = "<"   proxy   ">"
    webdriver.DesiredCapabilities.CHROME['proxy'] = {
        "httpProxy": PROXY,
        "ftpProxy": PROXY,
        "sslProxy": PROXY,
        "proxyType": "MANUAL",
    }

    #sleep
    sleep(20)

example file list proxy:

91.98.80.2:8080
183.221.221.149:9091
103.134.177.182:8888
103.110.162.210:80
103.151.226.46:8080
165.154.235.178:80
120.196.186.248:9091

I am using Selenium library

And of course I know my code has an error, but I can't find it :/

Thank you for helping me

CodePudding user response:

DesiredCapabilities is deprecated. You can replace your code under #set proxy with:

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % proxy)
chrome = webdriver.Chrome(chrome_options=chrome_options)
  • Related