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

在使用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浏览器 

扫描二维码关注公众号,回复: 6638249 查看本文章

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

  print(driver.title)

  driver.quit()






猜你喜欢

转载自blog.csdn.net/Excaliburrr/article/details/79164163