我最近把我的mac电脑升级到OS Catalina(v 10.15.3)。在这次升级之后,我无法使用硒启动chrome驱动程序。

当我运行selenium代码启动chrome浏览器时,我面临以下错误。

“chromedriver”无法打开,因为开发人员无法验证”。 “macOS无法验证此应用程序没有恶意软件。”

请帮帮我!


当前回答

解决此错误的最简单方法,请遵循以下步骤。

导航到你的chrome驱动程序保存/下载的地方 右击并选择Open with 选择使用终端打开 允许或选择yes 您应该在终端屏幕上看到一条成功消息 返回打开你的chrome驱动程序或IDE并运行,你应该不会再得到错误了

其他回答

The above answers were helpful. I would just add that if you're running Selenium from a development environment, in my case a Jupyter Notebook, and this is the issue, you're likely to see a PermissionError: [Errno 13] Permission denied error. There are other causes for this error, but it can be that macOS Catalina is blocking chromedriver from running for security reasons. Following the approaches above, I ran it from the command line and then was able to open it from Jupyter using driver = webdriver.Chrome('path/to/chromedriver).

现有的答案很好,而且很有效。

但是一个更简单的解决方案是打开终端并运行这个:

xattr -d com.apple.quarantine $(which chromedriver)

在macOS Catalina 10.15.6 (19G73)版本上对我有用的是

通过Homebrew安装chromedriver: 酿造安装chromedriver 然后,在Finder中单击Go菜单,然后单击Go to folder选项,并输入以下路由: /usr/local/Caskroom/chromedriver / 在那里你应该会看到一个文件夹,里面有你安装的chromedriver版本,就像这样: 88.0.4324.96 输入文件夹,您应该会看到chromedriver二进制文件。 右键点击它,然后点击打开

现在,你应该得到一个终端窗口弹出输出:

Last login: Sun Jan 31 12:29:15 on ttys001
/usr/local/Caskroom/chromedriver/88.0.4324.96/chromedriver ; exit;
   ~  /usr/local/Caskroom/chromedriver/88.0.4324.96/chromedriver ; exit;
Starting ChromeDriver 88.0.4324.96 (68dba2d8a0b149a1d3afac56fa74648032bcf46b-refs/branch-heads/4324@{#1784}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.

最后,按Ctrl+C停止执行并退出终端窗口。

现在你应该可以做水豚测试了。

更新到Mac OS Ventura 13.0后,您现在需要进入系统设置>隐私和安全。向下滚动到安全部分,你可以在那里看到chromedriver。单击Allow Anyway(它将提示输入管理凭据)。

(对我有用的,希望对你也有用)

所有macOS Big Sur 11.0用户更新:

使用自制软件安装chromedriver 酿造安装chromedriver 导航到Caskroom文件夹中的chromedriver /usr/local/bin/Caskroom/chromedriver……直到你看到Unix可执行文件“chromedriver” 按照苹果公司的建议,打开来自未知开发者的Mac应用程序,双击chromedriver,然后点击“打开”

对我来说,这导致一个终端窗口弹出输出:


Starting ChromeDriver ...
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.

我现在可以运行scrapy-selenium没有问题,你可以关闭终端窗口(是的,终止进程是OK的),它应该仍然工作而不停止你现在。

如果这对你有用,请告诉我