python - Chrome 版本自动安装 Chrome 驱动

标签 python selenium selenium-chromedriver

如果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/

相关文章:

python - 查看keras嵌入层的输出

python - 拆分数据框中的每个单元格( Pandas / python )

c# - 在加载了 firefox 插件的 selenium 中打开 firefox 窗口?

java - Web 元素之间的等待时间 [Webdriverwait Selenium]

javascript - Chrome 扩展程序可以修改 Window 对象,但无法创建新变量

python - Cython编译的app需要安装python吗?

python - Django 表单 ChoiceField 依赖于另一个 ChoiceField

java - 并行的 Selenium WebDriver - 关闭 WebDriver 实例会中断其他测试

java - 更改路径后,VB 脚本未执行 我看到 Windows 脚本主机提示符具有不同的路径

Java selenium headless (headless)模式下载 PDF 问题