Linux

linux(centOS)에서 python selenium 설치

I장군T 2024. 3. 27. 14:18
반응형

맥북에서 selenium을 사용해 작업했던것을 centOS환경으로 변경하는 과정에서의 삽질을 정리함

centOS에서의 삽질과정

 - python3, selenium4, vi, chrome 사용

selenium 설치는 문제없이 진행

pip install selenium
pip install webdriver_manager

문제는 크롬 버전..

yum install google-chrome

을 통해 설치하면 최신버전이 설치된다(내 기준으로 123.x.xxxx)

해당 버전으로는 driver를 못찾아 오류가 발생한다. 

그래서 그냥 크롬 다운그레이드하기로 결정.. 검색이 쉽지 않더군.. 그래도 찾음

 

2. 크롬 구버전을 검색

http://dist.control.lth.se/public/CentOS-7/x86_64/google.x86_64/

 

Index of /public/CentOS-7/x86_64/google.x86_64

 

dist.control.lth.se

3. 원하는 버전을 찾아 다운로드 후 설치

wget http://dist.control.lth.se/public/CentOS-7/x86_64/google.x86_64/google-chrome-stable-104.0.5112.101-1.x86_64.rpm
yum install ./google-chrome-stable-104.0.5112.101-1.x86_64.rpm

 

4. Python 소스 작성

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService

# 크롬 드라이버 최신 버전 ->버전에 맞는 드라이버를 찾아서 설치(따로 chrome driver 다운로드할 필요 없음)
service = ChromeService(executable_path=ChromeDriverManager().install())

 

 

오류 발생.. 버전문제인거 같음

    driver = webdriver.Chrome(service=service, options=options)
TypeError: __init__() got an unexpected keyword argument 'service'

 

그래서 그냥 버전을 명시했다.

from selenium import webdriver 

options = webdriver.ChromeOptions()
options.headless = True
options.add_argument("window-size=1920x1080")
options.add_argument("user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.79 Safari/537.36")

# chrome driver
driver = webdriver.Chrome("드라이브 경로/chromedriver", options=options)

 

성공...끝

반응형