Google Colab에서 Selenium 사용하기

2023. 7. 15. 14:30·Data Science
!pip install selenium
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
  1. Selenium 설치
  2. apt 업데이트
  3. chromedriver 설치
  4. 해당 경로에 설치한 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

 

'Data Science' 카테고리의 다른 글

토픽 모델링  (0) 2023.09.09
빈도분석  (0) 2023.07.22
데이터 크롤링  (0) 2023.07.15
데이터 시각화  (0) 2023.07.08
데이터 분석 기초  (0) 2023.07.01
'Data Science' 카테고리의 다른 글
  • 토픽 모델링
  • 빈도분석
  • 데이터 크롤링
  • 데이터 시각화
봄프로
봄프로
Data Scientist
  • 봄프로
    To be professional
    봄프로
    • 분류 전체보기 (59)
      • LLM (16)
      • Data Science (24)
      • ADP (8)
      • Domain (8)
      • Etc (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 인기 글

  • 태그

    오블완
    티스토리챌린지
    YOLO
    KBI
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.1
봄프로
Google Colab에서 Selenium 사용하기
상단으로

티스토리툴바