运行 Python 中带有代理的 Selenium Webdriver 未更改 IP
Running Selenium Webdriver with a proxy in Python not changing IP
我正在尝试使用 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()
编辑:我是 运行 根据以下代码的响应:
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()
但是网页中的ip总是一样的,不知道是不是理解错了代理的使用或者是我做错了什么
如果您使用火狐浏览器,
...
# 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)
如果你使用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)
我正在尝试使用 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()
编辑:我是 运行 根据以下代码的响应:
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()
但是网页中的ip总是一样的,不知道是不是理解错了代理的使用或者是我做错了什么
如果您使用火狐浏览器,
...
# 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)
如果你使用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)