Skip to content

Instantly share code, notes, and snippets.

@thanakijwanavit
Last active August 13, 2022 03:10
Show Gist options
  • Save thanakijwanavit/0381c712beb481b26bb9eeeb305d63bf to your computer and use it in GitHub Desktop.
Save thanakijwanavit/0381c712beb481b26bb9eeeb305d63bf to your computer and use it in GitHub Desktop.
how to run a headless selenium process in colab
#installation
!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/bin
import sys
sys.path.insert(0,'/usr/lib/chromium-browser/chromedriver')
from selenium import webdriver
chrome_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")
from PIL import Image
import io
r = wd.get_screenshot_as_png()
Image.open(io.BytesIO(r))
@thanakijwanavit
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment