我正在尝试将用户个人资料加载到chromedriver。它会弹出一个具有正确配置文件的浏览器窗口,但在加载网页之前会崩溃。我附上了代码和模糊的错误消息。你能告诉我我做错了什么吗?我搜索了stackoverflow,看起来这应该可行。谢谢!
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument("user-data-dir=C:\Users\ABC\AppData\Local\Google\Chrome\User Data")
browser = webdriver.Chrome(executable_path=chromedriverdir, chrome_options=chromeOptions)
browser.get('https://www.yahoo.com')
错误:
WebDriverException Traceback (most recent call last)
<ipython-input-4-b1d95c22d006> in <module>()
23 #chromeOptions.add_argument('window-size=1920x1200')
---> 25 browser = webdriver.Chrome(executable_path=chromedriverdir, chrome_options=chromeOptions)
26 browser.get('https://www.yahoo.com')
C:\ProgramData\Anaconda2\lib\site-packages\selenium\webdriver\chrome\webdriver.pyc in __init__(self, executable_path, port, chrome_options, service_args, desired_capabilities, service_log_path)
67 command_executor=ChromeRemoteConnection(
68 remote_server_addr=self.service.service_url),
---> 69 desired_capabilities=desired_capabilities)
70 except Exception:
71 self.quit()
C:\ProgramData\Anaconda2\lib\site-packages\selenium\webdriver\remote\webdriver.pyc in __init__(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector)
96 warnings.warn("Please use FirefoxOptions to set browser profile",
97 DeprecationWarning)
---> 98 self.start_session(desired_capabilities, browser_profile)
99 self._switch_to = SwitchTo(self)
100 self._mobile = Mobile(self)
C:\ProgramData\Anaconda2\lib\site-packages\selenium\webdriver\remote\webdriver.pyc in start_session(self, capabilities, browser_profile)
186 parameters = {"capabilities": w3c_caps,
187 "desiredCapabilities": capabilities}
--> 188 response = self.execute(Command.NEW_SESSION, parameters)
189 if 'sessionId' not in response:
190 response = response['value']
C:\ProgramData\Anaconda2\lib\site-packages\selenium\webdriver\remote\webdriver.pyc in execute(self, driver_command, params)
254 response = self.command_executor.execute(driver_command, params)
255 if response:
--> 256 self.error_handler.check_response(response)
257 response['value'] = self._unwrap_value(
258 response.get('value', None))
C:\ProgramData\Anaconda2\lib\site-packages\selenium\webdriver\remote\errorhandler.pyc in check_response(self, response)
192 elif exception_class == UnexpectedAlertPresentException and 'alert' in value:
193 raise exception_class(message, screen, stacktrace, value['alert'].get('text'))
--> 194 raise exception_class(message, screen, stacktrace)
195
196 def _value_or_default(self, obj, key, default):
WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist
(Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.17134 x86_64)