如何匹配 chromedriver 和 chrome 浏览器版本?

How to match chromedriver and chrome brower version?

提问人:Fastest Black 提问时间:11/6/2023 更新时间:11/6/2023 访问量:76

问:

在此处输入图像描述如何修复此错误? 帮帮我。

我正在尝试使用硒进行网络抓取。

如何匹配 chromedriver 和 chrome 浏览器版本? 如何修复此错误?

profile_name = 'File Downloader'
profile_path = rf'{os.path.expanduser("~")}\Chrome Profiles\{profile_name}'
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(f'user-data-dir={profile_path}')
chrome_options.add_argument(f'--profile-directory={profile_name}')
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument(f"--download.default_directory=Download_contanier")
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
chrome_options.add_experimental_option("detach", True)
browser = webdriver.Chrome(service=Service(executable_path="C:/chromedriver-win64/chromedriver.exe"), options=chrome_options)
browser.maximize_window()
谷歌-chrome selenium-webdriver selenium-chromedriver

评论


答:

0赞 Shawn 11/6/2023 #1

你使用什么版本的硒?如果是版本或更高版本,则让 Selenium Manager 处理 .您不必显式设置驱动程序的路径。4.6.0chromedriver.exe

因此,请更改以下代码:

browser = webdriver.Chrome(service=Service(executable_path="C:/chromedriver-win64/chromedriver.exe"), options=chrome_options)

自:

browser = webdriver.Chrome(service=Service(), options=chrome_options)

Selenium Manager 将检查您系统中的 chrome 浏览器版本,并相应地下载并使用匹配的 .chromedriver.exe

一些有用的参考资料: