파이썬
[selenium] 실행 후에 자동으로 창이 닫히지 않게 하기
모르는 개발자
2024. 5. 30. 14:02
창을 작업 후 놔두기
from selenium import webdriver
driver = webdriver.Chrome()
url = "https://www.naver.com"
driver.get(url)
기존 코드를 실행해 보았을 때, 네이버가 켜진 후 잠시 뒤 다시 닫혀버렸습니다.
전 창이 머물고 있으면 좋겠거든요.
그래서 옵션을 주기 위하여 Options를 import해주었습니다.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=chrome_options)
url = "https://www.naver.com"
driver.get(url)
그리고 ("detach", True) 옵션을 추가하여 스크립트가 실행된 후에 크롬이 꺼지지 않게 설정하였습니다.