Selenium Not Headless

41 views Asked by At

I want to monitor my crawling procedure by popping up a browser. I know I have to remove the --headless=new option in my code. However, without the option, my code is not working.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
import time

chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
chrome_options.add_argument('--headless=new')
chrome_options.add_argument('--no-sandbox')
service = Service()

# 불필요한 에러 메시지 없애기
#chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"])

# 브라우저 생성
browser = webdriver.Chrome(service=service, options=chrome_options)
browser.get('https://law.go.kr/')
time.sleep(3)

If I remove the 'headless' option, I find the error message below.

SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally.

(session not created: DevToolsActivePort file doesn't exist)

(The process started from chrome location /root/.cache/selenium/chrome/linux64/122.0.6261.111/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
0

There are 0 answers