셀리니움 “Chrome이 자동화된 테스트 소프트웨어에 의해 제어되고 있습니다” 없애기

웹사이트에서 접속하는 웹브라우저가 자동제어되는 웹브라우저인지 아닌지 알아낼 수 있습니다.

웹드라이버로 조종되고 있는지 아닌지를 웹 브라우저가 알려주도록 되어 있기 때문입니다. 그걸 이용해서 자동화해서 데이터를 가져가지 못하게 차단하는 웹사이트가 있습니다.

웹사이트에서 차단하지 못하게 웹드라이버로 조종되는지 알려주는 것들을 제거하거나 가리는 방법입니다.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
options = Options()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
# user-agent를 일반적인 브라우저와 비슷하게 설정
options.add_argument('--disable-blink-features=AutomationControlled')
# 크롬 드라이버 경로 설정
service = Service(executable_path="path_to_chromedriver")
driver = webdriver.Chrome(service=service, options=options)
# 필요한 작업 수행
driver.get('https://www.example.com')
# 작업 종료 후 드라이버 종료
driver.quit()

답글 남기기