硒铬中的代理

时间:2020-05-20 14:47:11

标签: python selenium selenium-webdriver selenium-chromedriver

我正在尝试在Selenium Chrome中使用代理,但是下面提供的所有方法均无效!代理从文件中提取为1.0.0.196:80。我尝试在PC和专用服务器上执行此操作-结果相同。如何解决?

方法1

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(f'--proxy-server={proxy}')
browser = webdriver.Chrome(options=chrome_options)

方法2

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(f'--proxy-server=http://{proxy}')
browser = webdriver.Chrome(options=chrome_options)

方法3

hostname = proxy[:proxy.find(':')]
port = proxy[proxy.find(':')+1:]

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % hostname + ":" + port)
browser = webdriver.Chrome(chrome_options=chrome_options)

方法4

desired_capabilities = webdriver.DesiredCapabilities.CHROME.copy()
desired_capabilities['proxy'] = {
    "httpProxy": proxy,
    "ftpProxy": proxy,
    "sslProxy": proxy,
    "noProxy": None,
    "proxyType": "MANUAL",
    "class": "org.openqa.selenium.Proxy",
    "autodetect": False
}

browser = webdriver.Chrome(desired_capabilities=desired_capabilities)

0 个答案:

没有答案