How can we use Selenium Webdriver in colab.research.google.com? How can we use Selenium Webdriver in colab.research.google.com? python python

How can we use Selenium Webdriver in colab.research.google.com?


You can do it by installing the chromium webdriver and adjusting some options such that it does not crash in google colab:

!pip install selenium!apt-get update # to update ubuntu to correctly run apt install!apt install chromium-chromedriver!cp /usr/lib/chromium-browser/chromedriver /usr/binimport syssys.path.insert(0,'/usr/lib/chromium-browser/chromedriver')from selenium import webdriverchrome_options = webdriver.ChromeOptions()chrome_options.add_argument('--headless')chrome_options.add_argument('--no-sandbox')chrome_options.add_argument('--disable-dev-shm-usage')wd = webdriver.Chrome('chromedriver',chrome_options=chrome_options)wd.get("https://www.webite-url.com")


this one worked in colab

!pip install selenium!apt-get update !apt install chromium-chromedriverfrom selenium import webdriverchrome_options = webdriver.ChromeOptions()chrome_options.add_argument('--headless')chrome_options.add_argument('--no-sandbox')chrome_options.add_argument('--disable-dev-shm-usage')driver = webdriver.Chrome('chromedriver',chrome_options=chrome_options)


I made my own library to make it easy.

!pip install kora -qfrom kora.selenium import wdwd.get("https://www.website.com")