我的代码是:
service = Service(executable_path=ChromeDriverManager().install())
options1 = Options()
options1.headless = True
driver1 = webdriver.Chrome(service=service, options=options1)
driver1.get("https://google.com")
然而,当我试图运行它时,我得到以下错误:selenium.common.exceptions.WebDriverException: Message: Service my path/chromedriver unexpectedly exited. Status code was: -9
我试着重新安装webdriver-manager,但是没有任何帮助。
您可以尝试使用SeleniumBase驱动程序管理器:
pip install seleniumbase
:
from seleniumbase import Driver
driver = Driver(browser="chrome", headless=True)
driver.get("https://google.com")
(虽然你不会看到浏览器,除非你设置headless
为False
)