【问题标题】:How do I set a proxy for chrome's webdriver in python如何在 python 中为 chrome 的 webdriver 设置代理
【发布时间】:2020-08-07 09:42:06
【问题描述】:

我已经尝试过: '''

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")

''' 以上代码取自how do i set proxy for chrome in python webdriver

我从谷歌浏览器收到一个错误,说 ERR_NO_SUPPORTED_PROXIES,即使我使用的是公共的。

【问题讨论】:

标签: python selenium-webdriver proxy selenium-chromedriver


【解决方案1】:

你可以试试这个:

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")

【讨论】:

  • 但您从未使用过capabilitieswebdriver.Chrome(desired_capabilities=capabilities)
猜你喜欢
  • 2012-07-12
  • 2019-01-19
  • 1970-01-01
  • 1970-01-01
  • 2013-01-19
  • 2019-04-04
  • 2017-09-09
相关资源
最近更新 更多