• 카테고리

    질문 & 답변
  • 세부 분야

    데이터 엔지니어링

  • 해결 여부

    해결됨

크롬드라이버 작동 후 꺼짐

20.12.02 22:40 작성 조회수 1.42k

0

셀레니움 모듈 설치 후 윈도우 c드라이버(C:/dev_python/Webdriver/chromedriver) 폴더에

크롬드라이버까지는 설치를 했고 아래 소스코드를 실행시키면 크롬 창이 열리긴 합니다. 

==============================================

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

chromedriver = 'C:/dev_python/Webdriver/chromedriver'

driver = webdriver.Chrome(chromedriver)

==============================================

문제는 열린 후에 저절로 종료가 되며 아래와 같은 에러 메시지가 뜨는데요..

---------------------------------------------------------------------------
WebDriverException                        Traceback (most recent call last)
<ipython-input-22-3fda3c2e7dab> in <module>
      3 
      4 chromedriver = 'C:/dev_python/Webdriver/chromedriver'
----> 5 driver = webdriver.Chrome(chromedriver)

~\anaconda3\lib\site-packages\selenium\webdriver\chrome\webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive)
     74 
     75         try:
---> 76             RemoteWebDriver.__init__(
     77                 self,
     78                 command_executor=ChromeRemoteConnection(

~\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in __init__(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options)
    155             warnings.warn("Please use FirefoxOptions to set browser profile",
    156                           DeprecationWarning, stacklevel=2)
--> 157         self.start_session(capabilities, browser_profile)
    158         self._switch_to = SwitchTo(self)
    159         self._mobile = Mobile(self)

~\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in start_session(self, capabilities, browser_profile)
    250         parameters = {"capabilities": w3c_caps,
    251                       "desiredCapabilities": capabilities}
--> 252         response = self.execute(Command.NEW_SESSION, parameters)
    253         if 'sessionId' not in response:
    254             response = response['value']

~\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params)
    319         response = self.command_executor.execute(driver_command, params)
    320         if response:
--> 321             self.error_handler.check_response(response)
    322             response['value'] = self._unwrap_value(
    323                 response.get('value', None))

~\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response)
    240                 alert_text = value['alert'].get('text')
    241             raise exception_class(message, screen, stacktrace, alert_text)
--> 242         raise exception_class(message, screen, stacktrace)
    243 
    244     def _value_or_default(self, obj, key, default):

WebDriverException: Message: unknown error: unable to discover open pages
  (Driver info: chromedriver=2.0,platform=Windows NT 6.2 x86_64)

에러의 원인이 무엇일까요?

답변 2

·

답변을 작성해보세요.

1

안녕하세요. 특이한 에러이긴 하네요. 저도 저런 에러를 유추하기는 어려운데요.

우선 chrome 버전도 최신으로 업데이트해보시고,

chromedriver도 해당 버전에 맞춰서 새로 다운로드받아보시면 어떨까 하고요.

다음으로 마지막 에러메세지를 검색해본 결과 다음과 같은 옵션을 써보시는 것도 좋을 것 같습니다.

https://stackoverflow.com/questions/52208663/selenium-common-exceptions-webdriverexception-message-unknown-error-unable-to

-----------------

Add the argument --no-sandbox through ChromeOptions() to your existing code as follows:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--no-sandbox') # Bypass OS security model
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://www.python.org')
print(driver.title)
driver.quit()

0

hobul님의 프로필

hobul

질문자

2020.12.03

크롬브라우저가 최신으로 업데이트가 안되어 있었습니다. 

최신 브라우저 버전과 맞는 크롬드라이버 설치후 코딩 실행하니 무사히 작동되었습니다..^^;

답변 감사합니다.  (_ . _)

파이썬 기초편 완강 후 크롤링 심화편과 MySQL 강좌 듣고 있습니다. 

좋은 강의 준비하시느라 고생하십니다. 잘 따라 가겠습니다.~