简体   繁体   English

在 Python 中使用代理运行 Selenium Webdriver 不会更改 IP

[英]Running Selenium Webdriver with a proxy in Python not changing IP

I am trying to make a proxy in python using selenium i have a list of free proxies from https://free-proxy-list.net/ but the ip i get is always the same, there is something wrong with this setup?我正在尝试使用 selenium 在 python 中创建代理我有一个来自https://free-proxy-list.net/的免费代理列表,但我得到的 ip 总是相同的,这个设置有问题吗?

PROXY = proxy_list[11]
options = Options()
options.headless = False

webdriver.DesiredCapabilities.FIREFOX['proxy'] = {
    "httpProxy":PROXY,
    "ftpProxy":PROXY,
    "sslProxy":PROXY,
    "noProxy":None,
    "proxyType":"MANUAL",
    "class":"org.openqa.selenium.Proxy",
    "autodetect":False
}
driver = webdriver.Firefox(options=options, executable_path=r'geckodriver.exe')
# Set the interceptor on the driver
driver.request_interceptor = interceptor 
driver.get(url)
time.sleep(5)
driver.quit()

EDIT: i am running according to the response the following code:编辑:我正在根据响应运行以下代码:

url = 'https://www.whatismyip.com/es/'
PROXY = proxy_list[6]
options = Options()
options.headless = False

firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['proxy'] = {
    'proxyType': "MANUAL",
    'httpProxy': PROXY,
    'ftpProxy': PROXY,
    'sslProxy': PROXY
}
driver = webdriver.Firefox(options=options, executable_path=r'geckodriver.exe', capabilities = firefox_capabilities)
# Set the interceptor on the driver
driver.request_interceptor = interceptor 
driver.get(url)
time.sleep(50)
driver.quit()

But the ip in the webpage is always the same, dunno if missunderstood the use of the proxy or i am doing something wrong但是网页中的ip总是一样的,不知道是不是误解了代理的使用或者我做错了什么

If you use Firefox browser,如果您使用火狐浏览器,

...
# set proxy
firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['proxy'] = {
    'proxyType': "MANUAL",
    'httpProxy': PROXY,
    'ftpProxy': PROXY,
    'sslProxy': PROXY
}
driver = webdriver.Firefox(options=options, executable_path=r'geckodriver.exe', capabilities = firefox_capabilities)

If you use Chrome,如果您使用 Chrome,

...
chrome_options = Options()
chrome_options.add_argument('--proxy-server=' + PROXY)
chrome_options.add_argument("--headless") 
driver = webdriver.Chrome(executable_path = 'chromedriver.exe', options=chrome_options)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM