반응형
① 초기 설치
⑴ python3 설치
https://www.python.org/downloads/
pip -V
pip3 -V
pip3 install virtualenv
⑵ 가상환경 설치
virtualenv <가상환경 이름>
virtualenv venv
source /venv/bin/activate
⑶ 가상환경에 selenium, chromedriver 설치
(venv)$ pip3 install selenium
# 크롬 브라우저 버전이 90 이하인 경우
(venv)$ brew install chromedriver
# 크롬 브라우저 버전이 91 이상인 경우
# https://chromedriver.chromium.org/downloads
② VSCode에서 python Extension 설치
③ python 파일 실행
⑴ review.py 파일 생성하기
from selenium import webdriver
driver = webdriver.Chrome('/usr/local/bin/chromedriver')
url = 'https://www.google.com'
driver.get(url)
⑵ 파일 실행하기
python review.py
이렇게 크롬에서 구글이 잘 열렸으면 됐다!
+@
# element name, class, id로 가져오기
# driver.find_element_by_name("name")
# driver.find_element_by_class_name("class")
# driver.find_element_by_id("id")
# element 클릭 => element.click()
# element 더블 클릭 => element.double_click()
# element 키보드 입력 전송 => element.send_keys()
# element로 마우스 이동 => element.move_to_element()
Updating Homebrew... 현상 해결
brew doctor
brew cleanup
brew doctor
This version of ChromeDriver only supports Chrome version 90
Current browser version is 97.0.4692.71 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome 해결
크롬 브라우저가 드라이버보다 버전이 높아서 그렇다
⑴ 드라이버 다운로드
https://chromedriver.chromium.org/downloads
여기서 현재 크롬 브라우저 버전과 동일한 드라이버를 다운로드한다
크롬 브라우저 버전은 아래에서 확인할 수 있다
우측 : 버튼 클릭 => 도움말 => Chrom 정보
⑵ /usr/local/bin 경로로 드라이버 이동
mv chromedriver /usr/local/bin
개발자를 확인할 수 없기 때문에 'chromedriver'을(를) 열 수 없습니다. 해결
xattr -d com.apple.quarantine /usr/local/bin/chromedriver
반응형