Data Science
Google Colab에서 Selenium 사용하기
봄프로
2023. 7. 15. 14:30
!pip install selenium
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
- Selenium 설치
- apt 업데이트
- chromedriver 설치
- 해당 경로에 설치한 chromedriver 복사
import selenium
print(selenium.__version__)
Selenium 버전 확인
# Selenium 버전이 3에서 4로 업그레이드되면서 from selenium.webdriver.common.by import By 실행
from selenium import webdriver
from selenium.webdriver.common.by import By
로컬 환경에서 Selenium을 실행하면 웹 브라우저 창 뜸
코랩에서는 웹 브라우저 창을 띄울 수 없기 때문에 별도의 설정 필요
창이 뜨지 않는 것은 운영체제가 리눅스 기반이기 때문으로 추정
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('chromedriver', options = options)
출처: https://github.com/googlecolab/colabtools/issues/3347#issuecomment-1537274499
Issues when trying to use Chromedriver in Colab · Issue #3347 · googlecolab/colabtools
I have been running a program for months that uses Selenium in Google Colab. I have not had an issue with it until tonight. Each time I try to run the webdriver, I get the following error: I've als...
github.com