我尝试在我的 jupyter 笔记本上编写此代码,它显示了错误。我的目标是进行网络抓取。
driver = webdriver.Chrome(ChromeDriverManager().install())
在此输入图像描述
我还使用 pip 安装了 selenium,也使用 pip 安装了 webdriver-manager。
的输出ChromeDriverManager().install()
is an executable_path
给司机,但是executable_path
被删除于selenium
4.10.0
。这就是为什么您在将值传递到后会看到错误webdriver.Chrome()
。以下是变化:https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e
注意executable_path
去掉了。如果你想传递一个executable_path
,你必须使用service
现在。 (service=Service(executable_path='./chromedriver')
)但是 Selenium Manager 现在完全包含在selenium
4.10.0
,所以这就是您所需要的:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service()
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()
如果在您的系统路径中找不到该驱动程序,Selenium Manager 将自动为您下载。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)