Ниже приведен мой код, который работает отлично, когда я запускаю его на локальном компьютере, но при попытке возникает ошибка. для запуска в блокноте Databricks
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
path = CHROME_PATH
path_download = DWNLD_PATH
chromeOptions = webdriver.ChromeOptions()
prefs = {"download.default_directory" : path_download}
chromeOptions.add_experimental_option("prefs", prefs)
chromeOptions.binary_location = '/usr/bin/google-chrome'
chromedriver = path
driver = webdriver.Chrome(keep_alive = chromedriver, options = chromeOptions)
chromeOptions.add_argument('--headless')
chromeOptions.add_argument('--no-sandbox')
chromeOptions.add_argument('--disable-dev-shm-usage')
driver.get('https://google.com')
search = driver.find_element(
by=By.ID,
value='UserName'
)
search.send_keys('xxxxxxxxxx') # USER-ID
search = driver.find_element(
by=By.ID,
value='Password'
)
search.send_keys('xxxxxxxx') # PASSWORD
search.send_keys(Keys.RETURN)
Ниже приведены выходные данные для версий chrome и chromedriver
%sh
/xxxxxxxxxxxx/path/chrome_chromedriver/chromedriver --version
google-chrome --version
ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052})
Google Chrome 114.0.5735.90
%sh which google-chrome
/usr/bin/google-chrome
То, что я пробовал до сих пор:
- пробовал запустить с опцией Headless Chrome
- Использовал одну и ту же версию Google Chrome и Chromedriver.
Я получаю следующую ошибку для код
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
#0 0x55a6c6f444e3
#1 0x55a6c6c73c76
#2 0x55a6c6c9cd78
#3 0x55a6c6c99029
#4 0x55a6c6cd7ccc
#5 0x55a6c6cd747f
#6 0x55a6c6ccede3
#7 0x55a6c6ca42dd
#8 0x55a6c6ca534e
#9 0x55a6c6f043e4
#10 0x55a6c6f083d7
#11 0x55a6c6f12b20
#12 0x55a6c6f09023
#13 0x55a6c6ed71aa
#14 0x55a6c6f2d6b8
#15 0x55a6c6f2d847
#16 0x55a6c6f3d243
#17 0x7f380e8e0ac3
File , line 12
10 chromeOptions.binary_location = '/usr/bin/google-chrome'
11 chromedriver = path
---> 12 driver = webdriver.Chrome(keep_alive = chromedriver, options = chromeOptions)
14 chromeOptions.add_argument('--headless')
15 chromeOptions.add_argument('--no-sandbox')
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-e2cd049b-f761-47d7-afec-72e21707b24c/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py:45, in WebDriver.__init__(self, options, service, keep_alive)
42 service = service if service else Service()
43 options = options if options else Options()
---> 45 super().__init__(
46 browser_name=DesiredCapabilities.CHROME["browserName"],
47 vendor_prefix="goog",
48 options=options,
49 service=service,
50 keep_alive=keep_alive,
51 )
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-e2cd049b-f761-47d7-afec-72e21707b24c/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py:66, in ChromiumDriver.__init__(self, browser_name, vendor_prefix, options, service, keep_alive)
57 executor = ChromiumRemoteConnection(
58 remote_server_addr=self.service.service_url,
59 browser_name=browser_name,
(...)
62 ignore_proxy=options._ignore_local_proxy,
63 )
65 try:
---> 66 super().__init__(command_executor=executor, options=options)
67 except Exception:
68 self.quit()
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-e2cd049b-f761-47d7-afec-72e21707b24c/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py:212, in WebDriver.__init__(self, command_executor, keep_alive, file_detector, options)
210 self._authenticator_id = None
211 self.start_client()
--> 212 self.start_session(capabilities)
214 self._websocket_connection = None
215 self._script = None
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-e2cd049b-f761-47d7-afec-72e21707b24c/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py:299, in WebDriver.start_session(self, capabilities)
292 """Creates a new session with the desired capabilities.
293
294 :Args:
295 - capabilities - a capabilities dict to start the session with.
296 """
298 caps = _create_caps(capabilities)
--> 299 response = self.execute(Command.NEW_SESSION, caps)["value"]
300 self.session_id = response.get("sessionId")
301 self.caps = response.get("capabilities")
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-e2cd049b-f761-47d7-afec-72e21707b24c/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py:354, in WebDriver.execute(self, driver_command, params)
352 response = self.command_executor.execute(driver_command, params)
353 if response:
--> 354 self.error_handler.check_response(response)
355 response["value"] = self._unwrap_value(response.get("value", None))
356 return response
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-e2cd049b-f761-47d7-afec-72e21707b24c/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py:229, in ErrorHandler.check_response(self, response)
227 alert_text = value["alert"].get("text")
228 raise exception_class(message, screen, stacktrace, alert_text) # type: ignore[call-arg] # mypy is not smart enough here
--> 229 raise exception_class(message, screen, stacktrace)
Подробнее здесь: https://stackoverflow.com/questions/790 ... databricks