[ 불편사항 ]
* python으로 웹 크롤링을 구현하였을 때 콘솔창이 뜨게 되는데 이 콘솔에 표시되는 복잡한 로그성 메시지들이 보인다.
* 문제는 이 로그성 메시지들이 내가 필요한 정보라기보다는 시스템적인 내용이 대부분이라는 것이다.
* 프로그램 작성 오류나 워닝 메시지일 경우는 도움이 되는데 개발자와 상관없는 내용들이기 때문에 불필요한 메시지일 뿐이다.
* 아래의 화면에서 빨간색으로 표시해 둔 메시지들이 여기에 해당된다.
[ 해결방법 ]
* 셀레니움 모듈에서 웹드라이버를 선언할 때 Chrome 드라이버의 옵션을 다루는 Options 클래스를 import 한 후,
* 불필요한 콘솔 메시지를 제거하도록 설정하면 아래와 같은 불필요한 시스템 메시지들이 표시되지 않는다.
* 해당 소스코드는 아래에 변경 전/후 구분하였고, 밑줄 그은 부분만 참고하면 된다.
<변경전>
from selenium import webdriver
from selenium.webdriver.common import keys
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
browser = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
browser.get('https://www.google.co.kr/')
<변경후>
from selenium import webdriver
from selenium.webdriver.common import keys
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options # Chrome 브라우저 Options 클래스를 가져온다.
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging']) # 불필요한 콘솔 메시지를 제거한다.
browser = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
browser.get('https://www.google.co.kr/')
'파이선 (python)' 카테고리의 다른 글
[Python] 비동기(Async) 방식 프로그램을 구현해보자 (2) | 2023.10.03 |
---|---|
[Python] 스레드(Thread)를 구현해보자 (0) | 2023.10.03 |
[Python] Twilio SMS 유료 결제하기 (0) | 2023.07.30 |
[Python] Chrome Driver 없이 자동실행 (0) | 2023.07.27 |
[Python] 설치 및 기본환경 구성방법 (0) | 2023.07.23 |