WebDriverException: Message: Service /content/chromedriver unexpectedly exited. Status code was: -6 with ChromeDriver Google Colab and Selenium

白昼怎懂夜的黑 提交于 2019-11-28 09:33:40
DebanjanB

This error message...

WebDriverException: Message: Service /content/chromedriver unexpectedly exited. Status code was: -6

...implies that the ChromeDriver exited unexpectedly.

Your main issue is the incompatibility between the version of the binaries you are using as follows:

  • As per the line of code:

    !wget "http://chromedriver.storage.googleapis.com/2.25/chromedriver_linux64.zip"
    
  • You are using chromedriver=2.25

  • Release Notes of chromedriver=2.25 clearly mentions the following :

Supports Chrome v53-55

  • Though you haven't mentioned the version of Chrome Browser it is expected you are using one of the latest Chrome Browser releases.

So there is a clear mismatch between ChromeDriver v2.33 and the recently released Chrome Browser versions.

Solution


Update

I am not sure about google-colaboratory. The bottomline is you have to use the matching version of ChromeDriver with respect to the prevailing version of Google Chrome version installed.

However, you need to find a way to install Chrome or Chromium on Colab first. Then, you can use !wget and !unzip to download, unzip and start using the matching ChromeDriver version.

You can find a discussion on the compatibility between ChromeDriver and Chrome Browser in this discussion

Himanshu Poddar

I have found the answer to the question about why I was getting an error. Please install the chromium-chromedriver and add it to your path variable as well as the bin directory. This is the full fledge solution to the problem "how to scrape data using selenium on colab". There is one more method by using PhantomJS but this API has been deprecated by selenium and hopefully they will remove it in the next selenium update.

# install chromium, its driver, and selenium
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
!pip install selenium
# set options to be headless, ..
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
# open it, go to a website, and get results
wd = webdriver.Chrome('chromedriver',options=options)
wd.get("https://www.website.com")
print(wd.page_source)  # results

This would work for anyone who want to scrape their data on google colab and not on your local machine. Please execute the steps as shown sequentially in the same order. You can find the notebook here https://colab.research.google.com/drive/1GFJKhpOju_WLAgiVPCzCGTBVGMkyAjtk .

This may not directly help you. But if eventually, you can't install Chrome + selenium, you can still use phantomjs + selenium. Like this notebook:

https://colab.research.google.com/drive/1V62zhjw2V5buxdN1s9mqkLzh3FWqSq8S

But I would prefer Chrome, if possible.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!