I am trying to use Selenium in Google Colab, but I get some errors when I try to run a Firefox instance. i followed this links:
- Selenium Documentation here, I tried with the Driver Management Software but I got the error that says that was unable to find the binary location to Firefox. So I tried with the Hard Coded Location method, but I still have the same error, so I think that I must install firefox in google colab, but I don't know if this is a correct approach
Here is my code:
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager
from google.colab import drive
drive.mount('/content/drive', force_remount=True)
service = FirefoxService(executable_path= '/content/drive/MyDrive/geckodriver')
driver = webdriver.Firefox(service=service)
And this is the entire error:
SessionNotCreatedException Traceback (most recent call last)
<ipython-input-7-51ea1584f592> in <module>()
1 service = FirefoxService(executable_path= '/content/drive/MyDrive/geckodriver')
----> 2 driver = webdriver.Firefox(service=service)
4 frames
/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/errorhandler.py in check_response(self, response)
245 alert_text = value['alert'].get('text')
246 raise exception_class(message, screen, stacktrace, alert_text) # type: ignore[call-arg] # mypy is not smart enough here
--> 247 raise exception_class(message, screen, stacktrace)
248
249 def _value_or_default(self, obj: Mapping[_KT, _VT], key: _KT, default: _VT) -> _VT:
SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
Edit
i tried installing firefox on Google colab, and i think all is correct, but when it tried to run firefox i get this output on geckodriver.log:
1643070515477 geckodriver INFO Listening on 127.0.0.1:43355
1643070515979 mozrunner::runner INFO Running command: "/usr/bin/firefox" "--marionette" "--headless" "--no-sandbox" "--disable-dev-shm-usage" "--remote-debugging-port" "43945" "-no-remote" "-profile" "/tmp/rust_mozprofileeDGKcf"
src/tcmalloc.cc:283] Attempt to free invalid pointer 0x7fe67e416250
Redirecting call to abort() to mozalloc_abort
Here is the code:
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager
from google.colab import drive
drive.mount('/content/drive', force_remount=True)
service = FirefoxService(executable_path= '/content/drive/MyDrive/geckodriver')
options = webdriver.FirefoxOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Firefox(service= service, options= options)