Я пишу скребок с использованием Selenium, и он работал нормально до 15 минут go .. Внезапно я получаю следующую ошибку при каждом выполнении. Это мой код:
searchDate = wait.until(EC.element_to_be_clickable((By.XPATH, "/input[@placeholder='select sold date range']")))
searchDate.click()
time.sleep(5)
И ошибка:
WebDriverException: Message: chrome not reachable
(Session info: chrome=80.0.3987.163)
И мой chrome параметр:
options = webdriver.ChromeOptions()
prefs = {'download.default_directory': new_dir}
options.add_experimental_option('prefs', prefs)
browser = webdriver.Chrome(executable_path = r'C:/Program Files/chromedriver/chromedriver.exe')
Я пытался решить проблему с помощью Цепочка опций, как предложил другой пост, таких как:
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
prefs = {'download.default_directory': new_dir}
options.add_experimental_option('prefs', prefs)
browser = webdriver.Chrome(executable_path = r'C:/Program Files/chromedriver/chromedriver.exe', chrome_options=options)
Но я все еще получаю точно такую же ошибку. Почему это произошло?
Любой совет будет с благодарностью!
++
---------------------------------------------------------------------------
WebDriverException Traceback (most recent call last)
<ipython-input-102-c7d533e1df88> in <module>
----> 1 wait.until(EC.visibility_of_element_located((By.XPATH,"//input[@name='daterangepicker_start']"))).click()
2
3
~\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\support\wait.py in until(self, method, message)
69 while True:
70 try:
---> 71 value = method(self._driver)
72 if value:
73 return value
~\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\support\expected_conditions.py in __call__(self, driver)
126 def __call__(self, driver):
127 try:
--> 128 return _element_if_visible(_find_element(driver, self.locator))
129 except StaleElementReferenceException:
130 return False
~\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\support\expected_conditions.py in _find_element(driver, by)
413 raise e
414 except WebDriverException as e:
--> 415 raise e
416
417
~\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\support\expected_conditions.py in _find_element(driver, by)
409 if thrown."""
410 try:
--> 411 return driver.find_element(*by)
412 except NoSuchElementException as e:
413 raise e
~\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webdriver.py in find_element(self, by, value)
976 return self.execute(Command.FIND_ELEMENT, {
977 'using': by,
--> 978 'value': value})['value']
979
980 def find_elements(self, by=By.ID, value=None):
~\AppData\Roaming\Python\Python37\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))
~\AppData\Roaming\Python\Python37\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: chrome not reachable
(Session info: chrome=81.0.4044.92)