首页 > 解决方案 > Selenium.common.exceptions.WebDriverException:消息:未知错误:找不到 Chrome 二进制文件

问题描述

我正在尝试将我日常在线做的一些事情自动化,并获得一些网络抓取经验。我看到一些关于 Selenium 和 Python 对初学者有好处的东西,我想我会试一试。我最终得到了一个简单的脚本来在我的家用计算机上工作,但它在我提供的路径上找不到 Chrome 二进制文件,我不知道该怎么做。

我用它来将我的 PATH 环境变量设置为包含我的 chromedriver https://youtu.be/dz59GsdvUF8的目录

我从https://sites.google.com/a/chromium.org/chromedriver/下载了 ChromeDriver 74.0.3729.6(最新稳定版本)

我正在使用 python3、Visual Studio 代码和 Ubuntu,如果其中任何一个重要的话。

import time 
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

#Stack overflow said to try this but could not make it work
#opts = webdriver.ChromeOptions()
#opts.binary_location = "C:\webdrivers\chromedriver.exe"
#browser = webdriver.Chrome(chrome_options=opts)

#this is where my chrome is
#C:\Users\tucker.steven2\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Virtual Programs\Google Chrome\Chrome v62

#I have a chromedriver in the same directory as my python code
browser = webdriver.Chrome('chromedriver.exe')
browser.get(https://www.something.com/) #just a generic site
browser.quit()

我的预期结果是打开一个 chrome 窗口到 Hulu 的网站,我得到的错误是:

selenium.common.exceptions.WebDriverException:消息:未知错误:找不到 Chrome 二进制文件(驱动程序信息:chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),平台=Windows NT 10.0.16299 x86_64)

标签: python-3.xseleniumselenium-webdriver

解决方案


如果您使用的是 Linux 发行版 Ubuntu,那么您的路径全错了。YouTube 视频适用于 Windows。Linux 上的文件结构完全不同。请使用您尝试运行它的当前操作系统进行更新。此外,您无需编写脚本 - 只需打开 hulu。您可以创建一个快捷方式并将其放在桌面上。如果您正在尝试做一些需要很长时间才能完成的更复杂的事情,那将是制作 selenium 脚本的更好用例。我知道您正在努力学习这一点,这是值得称赞的。如果您真的将 Ubuntu 作为您的操作系统,那么您将有一个/usr/bin文件夹来存放您的程序。如果您正在运行 Windows,它将是C:\Users\"Your User Name Goes Here"\Documents或您要去的地方。

程序将在C:\Program Files\或中C:\Program Files(x86)。我建议您观看一些有关操作系统路径的 YouTube 视频。

答案取决于您的操作系统以及您保存程序的位置。


推荐阅读