错误是:
TypeError: WebDriver.__init__() got multiple values for argument 'options'
`
代码是:
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
browser = webdriver.Chrome(r'/usr/bin/chromedriver', options=chrome_options)
这是错误:
TypeError Traceback (most recent call last)
<ipython-input-5-9a7e59e392ae> in <cell line: 6>()
4 chrome_options.add_argument('--headless')
5
----> 6 browser = webdriver.Chrome(r'/usr/bin/chromedriver', options=chrome_options)
TypeError: WebDriver.__init__() got multiple values for argument 'options'
这是由于
selenium
4.10.0
的变化所致:
https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e
请注意,第一个参数不再是
executable_path
,而是 options
。 (这就是为什么它抱怨你两次传递它。)
如果您想传递
executable_path
,您现在必须使用 service
参数。
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service(executable_path=r'/usr/bin/chromedriver')
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service(executable_path=r"..\chromedriver.exe")
driver = webdriver.Chrome(service=service)
#它对我有用,希望 selenium 版本 4.1 chrome 116 最新版