如果chrome驱动的版本和当前的chrome版本不同,我想写一个python代码,下载并运行与当前chrome版本匹配的chrome驱动。
这就是我一直在寻找的东西
driver = webdriver.Chrome(ChromeDriverManage().install(), chrome_options=chrome_options)
我认为这段代码效率低下,因为我每次都必须安装 chrome 驱动程序。 有什么办法吗?
最佳答案
官方文档是这么说的:
你可以做到
pip install chromedriver-autoinstaller
或
导入
import chromedriver_autoinstaller
代码:
from selenium import webdriver
import chromedriver_autoinstaller
chromedriver_autoinstaller.install() # Check if the current version of chromedriver exists
# and if it doesn't exist, download it automatically,
# then add chromedriver to path
driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title
引用:click here
关于python - Chrome 版本自动安装 Chrome 驱动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67513427/