[Crawling] Chromedriver setting (ubuntu)

UNGGI LEE·2023년 9월 22일
0

Chrome CLI 설치

구글 크롬은 ubuntu에 cli로 설치하기 위해서는 아래 절차를 따르면 된다.

apt update -y
apt upgrade -y
apt install wget
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
apt install ./google-chrome-stable_current_amd64.deb

Chromedriver 설치

먼저, 설치한 Chrome의 버전을 확인해보자

google-chrome --version

> Google Chrome 117.0.5938.92 (예시)

다음으로 아래 링크에서 해당 버전에 맞는 Chromedriver를 설치하면 된다.

https://chromedriver.chromium.org/downloads

다운받은 Chromedriver의 압축을 해제하고, 파일을 원하는 위치로 옮기면 된다. 이때 경로가 기본 경로면 별도로 코드에서 지정하지 않아도 된다.

// Move file to a directory that's already in PATH
sudo mv ~/Downloads/chromedriver /usr/local/bin

// Make file executable
sudo chmod +x /usr/local/bin/chromedriver

Basic selenium code

아래 명령어를 실행할때 이상없이 작동하면 성공..!

from selenium import webdriver
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
options.add_argument('--disable-gpu')
options.add_argument('--headless')
options.add_argument('--no-sandbox')  # sandbox를 사용하지 않는다는 옵션!! 필수
options.add_argument('--disable-blink-features=AutomationControlled')
driver = webdriver.Chrome(options=options)

# Navigate to Naver Terms
driver.get("https://www.google.co.kr")

print(driver)

driver.quit()

Reference

https://askubuntu.com/questions/1235957/how-to-add-chromedriver-to-path-in-ubuntu

profile
NLP Researcher & ML Engineer @i-Scream Edu

0개의 댓글