Skip to content

Instantly share code, notes, and snippets.

@soiqualang
Forked from korakot/selenium.py
Created April 16, 2021 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soiqualang/6e1f329ac4604151385b85a89da68735 to your computer and use it in GitHub Desktop.
Save soiqualang/6e1f329ac4604151385b85a89da68735 to your computer and use it in GitHub Desktop.
Use selenium in Colab
# install chromium, its driver, and selenium
!apt update
!apt install chromium-chromedriver
!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(options=options)
wd.get("https://www.website.com")
print(wd.page_source) # results
# divs = wd.find_elements_by_css_selector('div')
# I create my own library to make it even easier
!pip install kora -q
from kora.selenium import wd
wd.get("https://www.website.com")
print(wd.page_source) # results
# I add a few helpers
divs = wd.select("div") # css selecter
div = divs[0]
span = div.select1("span") # return the first result
wd # screenshot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment