重装系统后:selenium无法找到chrome--报错selenium.common.exceptions.WebDriverException: Message: unknown error: c

重装系统后:selenium无法找到chrome--selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary

一、报错

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary

在这里插入图片描述

翻译过来为:selenium.common.exceptions.WebDriverException:消息:未知错误:找不到Chrome二进制文件

即找不到chrome浏览器

二、解决方法

添加chrome路径:

ops.binary_location = r'I:\Program Files (x86)\Google\Chrome\Application\chrome.exe'

ops是传递给option的对象
完整为:

from selenium.webdriver.chrome.options import Options
ops.binary_location = r'I:\Program Files (x86)\Google\Chrome\Application\chrome.exe'(此处是我的chrome位置,需要在r""中填上自己的chrome位置)
browser = webdriver.Chrome(options=ops)

在这里插入图片描述
这个是我自己设置的输出,出现代表着正确

三、第二个报错:

selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chrome

连接错误,需要

ping localhost

如果为ping的结果为:
一般错误
一般错误
一般错误
这样的结果
则存在错误

四、解决方法:

关闭防火墙
在这里插入图片描述
在这里插入图片描述
再次,

ping localhost

在这里插入图片描述
参见《mac selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedri》链接: link.

猜你喜欢

转载自blog.csdn.net/python__reported/article/details/106267149