如何在python中为chrome的webdriver设置代理?

问题描述 投票:0回答:1

我已经试过了:'''

from selenium import webdriver

PROXY = "23.23.23.23:3128" # IP:PORT or HOST:PORT

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

chrome = webdriver.Chrome('./chromedriver',options=options) #<----- I used './chromedriver' to set a PATH
chrome.get("http://whatismyipaddress.com")

''以上代码取自 如何在python webdriver中设置chrome的代理。.

我从google chrome得到一个错误,说ERR_NO_SUPPORTED_PROXIES,甚至当我使用公共的。

python selenium-webdriver proxy selenium-chromedriver
1个回答
0
投票

你可以试试这个。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

PROXY = "23.23.23.23:3128" # IP:PORT or HOST:PORT

capabilities = dict(DesiredCapabilities.CHROME)
capabilities['proxy'] = {'proxyType': 'MANUAL','httpProxy': '23.23.23.23:3128','ftpProxy': '23.23.23.23:3128','sslProxy': '23.23.23.23:3128','noProxy': '','class': "org.openqa.selenium.Proxy",'autodetect': False}
chrome_options = Options()
chrome_options.add_argument("--disable-notifications")
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--verbose')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-software-rasterizer')
chrome_options.add_argument('--headless')
chrome = webdriver.Chrome('./chromedriver',options=chrome_options) #<----- I used './chromedriver' to set a PATH
chrome.get("http://whatismyipaddress.com")
© www.soinside.com 2019 - 2024. All rights reserved.