簡體   English   中英

selenium.common.exceptions.WebDriverException:消息:服務 chromedriver 意外退出

[英]selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited

我知道已經有人問過非常相似的問題,但即使經過幾個小時的谷歌搜索、研究和比較,我也無法弄清楚問題是什么。 我的最終目標是使用 selenium 用 Python 進行一些網絡抓取,但現在我什至無法啟動 webdriver。 這是到目前為止我得到的代碼和錯誤消息:

$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyvirtualdisplay import Display
>>> from selenium import webdriver
>>> 
>>> display = Display(visible=0, size=(1024, 768))
>>> display.start()
<Display cmd_param=['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '1024x768x24', ':1069'] cmd=['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '1024x768x24', ':1069'] oserror=None return_code=None stdout="None" stderr="None" timeout_happened=False>
>>> d = webdriver.Chrome()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 96, in start
    self.assert_process_still_running()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
    % (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1

chromedriver 版本為 2.30,位於:

$ ll /usr/local/bin/chromedriver
-rwxr-xr-x 1 stefan stefan 8475456 Jun  7 15:53 /usr/local/bin/chromedriver

由於它在/usr/local/bin ,因此在實例化 webdriver 時不需要指定路徑,如d = webdriver.Chrome("/path/to/chromedriver")

在我能夠運行上面的代碼之前,我安裝了谷歌 Chrome 瀏覽器、xvfb、pyvirtualdisplay 和 selenium。 我在其中使用的命令:

sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb
sudo apt-get install -f
sudo apt-get install xvfb
wget -N http://chromedriver.storage.googleapis.com/2.30/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/local/bin
sudo pip install pyvirtualdisplay selenium

所以,我擁有所有軟件的最新版本。 非常感謝有關解決我的問題的方法的任何幫助。 非常感謝您提前。

當我通過nohup使用 selenium 和 PhantomJs 驅動程序運行進程時遇到了同樣的問題(也在那里提到)我需要在虛擬機中捕獲輸出而不依賴於打開的會話。

為此,我開始使用tmux ,它不會像 nohup 那樣阻塞信號,並且問題已經消失。

將 chromedriver.exe 和您的程序放在同一目錄中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM