解决Mac环境下Can not connect to the Service chromedriver

本文介绍了在Mac环境中使用Python和Selenium时遇到的常见错误,包括WebDriverException和无法连接到服务的问题,并提供了详细的解决方案,如环境变量配置及localhost的设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在使用Mac+python+selenium中出现报错:

1. selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
2. Can not connect to the Service chrome-driver

解决方法:

 1. 确保你的webdriver(如safaridriver、phantomjs等)已经下载并解压存放在你的环境变量目录下 

  我的存放目录:/usr/bin/chromedriver

  检查方式:terminal中输入which chromedriver

 2.如果仍然不行,请尝试 ping localhost

  在缺失127.0.0.1 localhost的情况下,会出现Cannot connect to the service... 错误,修改之后selenium使用正常

   测试代码:

  from selenium import webdriver 

  driver = webdriver.Chrome() # 这里调用chrome浏览器 

  driver.get('https://www.baidu.com')  

  print(driver.title)

  driver.quit()






评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值