在我几天前的最后一次使用之后,我还没能开始使用python的selenium webdriver。根据错误消息,它在上次使用时意外退出,现在,重新启动我的macbook后,卸载并重新安装chromedriver / selenium:
brew rmtree chromedriver && brew install chromedriver
pip uninstall selenium && pip install selenium
我还在同一个地方。它似乎是selenium本身,因为对于Firefox和Chrome,我都会收到错误消息。
我试图在python3.5内核上运行的是:
from selenium import webdriver
driver = webdriver.Chrome()
堆栈跟踪:
File "/Users/myuser/webscraping/env/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py",
line 62, in __init__self.service.start()
File "/Users/myuser/webscraping/env/lib/python3.5/site-packages/selenium/webdriver/common/service.py",
line 86, in start self.assert_process_still_running()
File "/Users/myuser/webscraping/env/lib/python3.5/site-packages/selenium/webdriver/common/service.py",
line 99, in assert_process_still_running % (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: -5
同样,对于Firefox:
from selenium import webdriver
driver = webdriver.Firefox()
和
File "/Users/myuser/webscraping/env/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py",
line 80, in __init__
self.binary, timeout)
File "/Users/myuser/webscraping/env/lib/python3.5/site-packagesyuser/selenium/webdriver/firefox/extension_connection.py",
line 52, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "/Users/myuser/webscraping/env/lib/python3.5/site-packages/selenium/webdriver/firefox/firefox_binary.py",
line 68, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "/Users/myuser/webscraping/env/lib/python3.5/site-packages/selenium/webdriver/firefox/firefox_binary.py",
line 99, in _wait_until_connectable
"The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect.
If you specified a log_file in the FirefoxBinary constructor, check it for details.
我应该寻找一些流氓程序来杀死ps -e
和kill -sigint
吗?
答案 0 :(得分:0)
我发现自制的chromedriver抛出了与符号化正确的dylib有关的错误。我按照this回答中的步骤修复了问题,让chromedriver再次运行,这使得selenium / chrome webdriver也能正常工作。