如何在 Mac 上解决此 Selenium 异常,该异常显示“无法访问 chrome”?

How do I resolve this Selenium exception on a Mac thats says "chrome not reachable"?

提问人:Kudzie99 提问时间:5/18/2021 更新时间:5/18/2021 访问量:196

问:

我正在尝试学习如何使用 Selenium 自动化 Web 流程,并希望能够构建强大的网络爬虫和其他东西。所以,我刚刚完成了 Pycharm 和 Selenium 的安装,我只是试图运行一个简单的代码片段,在 chrome 中打开一个网页,没有什么太花哨的。我的代码如下(当然是用 Python 编写的)

from selenium import webdriver


PATH = "/Users/Kudzie/Tools/chromedriver"
driver = webdriver.Chrome(PATH)
driver.get('https://orbitrevolution.tech')

所以,当我运行这段代码时,我得到了这个异常,我不知道如何解决这个问题,我尝试阅读这个问题的过去变体,但我似乎没有得到有效的解决方案。例外情况如下

Traceback (most recent call last):
  File "/Users/Kudzie/PycharmProjects/Web Scraper/main.py", line 5, in <module>
    driver = webdriver.Chrome(PATH)
  File "/Users/Kudzie/PycharmProjects/Web Scraper/venv/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
    RemoteWebDriver.__init__(
  File "/Users/Kudzie/PycharmProjects/Web Scraper/venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/Users/Kudzie/PycharmProjects/Web Scraper/venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Users/Kudzie/PycharmProjects/Web Scraper/venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Users/Kudzie/PycharmProjects/Web Scraper/venv/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable


Process finished with exit code 1

python selenium 网页抓取 selenium-chromedriver chrome-web-driver

评论


答:

1赞 JD2775 5/18/2021 #1

尝试替换它:

driver = webdriver.Chrome(PATH)

有了这个:

driver = webdriver.Chrome(executable_path=PATH)

评论

0赞 Kudzie99 5/18/2021
我试过了,现在我有一个不同的错误selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist
0赞 JD2775 5/18/2021
嗯,不确定那个。这可能需要一个新的问题,这样就不会迷失在混合中,我知道我给你的作品是需要的,但听起来好像还有其他事情在发生。
0赞 Kudzie99 5/18/2021
好的,感谢您抽出宝贵时间回复