Last active
August 13, 2022 03:10
-
-
Save thanakijwanavit/0381c712beb481b26bb9eeeb305d63bf to your computer and use it in GitHub Desktop.
how to run a headless selenium process in colab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import io | |
r = wd.get_screenshot_as_png() | |
Image.open(io.BytesIO(r)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://bit.ly/3bruAMt