使用python中的API下载chromedriver

xxls0lw8  于 12个月前  发布在  Go
关注(0)|答案(1)|浏览(97)

我们有一个Python自动化解决方案,我们使用Chrome浏览器。
使用以下代码创建Chrome对象:
driver = webdeiver.Chrome(executable_path=r“chromedriver.exe”)
问题是,如果Chrome浏览器更新,我们需要更换相同版本的Chrome驱动程序。
为了下载它,我们使用下面的API下载chromedriver zip文件。
https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/{version}/win32/chromedriver-win32.zip
由于我们的Chrome浏览器版本是177.0.5938.149,因此我们使用Chrome来测试API。
但是,测试实验室中不存在此版本,最新版本API中也不存在此版本。
我在哪里使用Web API获得这个特定版本?

f4t66c6m

f4t66c6m1#

您可以使用软件包webdriver_manager
pip install webdriver_manager
ChromeDriverManager()接受版本作为参数

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

option = webdriver.ChromeOptions()
option.add_argument("start-maximized")
version = "177.0"
driver = webdriver.Chrome(service=Service(ChromeDriverManager(version=version).install()),options=option)
driver.get('https://www.google.com/')

相关问题