작성
·
163
·
수정됨
0
안녕하세요
셀레늄을 소개하는 다음 웹페이지 https://wikidocs.net/177133#_2
를 보고 해보고 있는데요.
실행했을 때 네이버 화면이 로드 되다가 도중에 꺼져버립니다.
어덯게 해결하면 좋을까요?
자료화면 링크걸었습니다.
https://drive.google.com/file/d/1ZdA5RIf0NZnbY-8-_Tkf2wNf3RVTsXS5/view?usp=sharing
vs code, window11 환경입니다.
# 방법1
# from seleniumwire import webdriver
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
options = webdriver.ChromeOptions()
# options.add_argument("headless")
# mobile_emulation = { "deviceName": "iPhone 12 Pro" }
# options.add_experimental_option("mobileEmulation", mobile_emulation)
# options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36")
options.add_experimental_option('excludeSwitches', ['enable-logging']) # 콘솔로그 출력 안하게
options.add_experimental_option("excludeSwitches", ["enable-automation"]) # 자동화 제어 메시지 제거
options.add_experimental_option("useAutomationExtension", False) # 자동화 확장기능 비활성화
options.add_argument('--disable-blink-features=AutomationControlled') # 자동화 탐지 회피
service = Service()
driver = webdriver.Chrome(service=service, options=options)
driver.get("https://www.naver.com")
driver.quit()
답변 2
0
답변 감사합니다. 2번 3번 시도해보았으나 효과없었습니다. 1번의 경우 정해둔 시간이 지나면 다시 꺼지니 별로 의미가 없는 것 같습니다. 웹페이지가 열린 상태로 유지시키고 싶은데요.
0
안녕하세요, 인프런 AI 인턴입니다.
셀레늄으로 웹페이지를 로드하는 도중 꺼지는 문제는 여러 가지 원인으로 발생할 수 있습니다. 전성원님께서 코드를 제공해주셨기 때문에, 코드에 근거하여 몇 가지 해결 방안을 제안해 드리겠습니다.
driver.quit()
구문이 실행되어 바로 드라이버가 종료됩니다. 웹페이지 로드를 확인하고 싶으시다면, time.sleep()
함수를 사용하여 몇 초간 기다린 후 종료하도록 수정해 보세요.import time # time 모듈을 import
# (중략)
driver.get("https://www.naver.com")
time.sleep(5) # 5초 동안 기다림
driver.quit()
크롬 옵션 문제: 때로는 크롬 옵션 설정이 웹페이지 로드에 영향을 줄 수 있습니다. 예를 들어, ‘headless’ 모드나 다른 옵션들이 문제를 일으킬 수 있습니다. 문제 해결을 위해 하나씩 주석 처리하여 어떤 옵션이 문제인지 확인해 보세요.
드라이버 호환성 문제: 사용 중인 웹드라이버와 크롬 브라우저의 버전이 호환되는지 확인하세요. webdriver_manager
를 사용하고 계시니, 일반적으로는 자동으로 호환되는 드라이버를 관리해 주겠지만, 가끔 호환 문제가 발생할 수 있습니다.
문제가 지속된다면, 셀레늄과 관련된 커뮤니티나 stackoverflow
에 동일한 문제를 경험한 다른 개발자의 해결 방법을 찾아보시는 것도 좋은 방법입니다.
시도해보시고도 해결되지 않는 경우, 더 구체적인 오류 메시지나 상황을 알려주시면 추가적으로 도움을 드리도록 하겠습니다.