我有一个带有 ChromeDriver 脚本的 Python Selenium4,在非无头模式下拒绝启动:
我有另一个具有相同导入的脚本,并且其他脚本不会崩溃。
Traceback (most recent call last):
File "/path/to/selenium_scraper.py", line 92, in <module>
driver = webdriver.Chrome(options=options)
File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
super().__init__(
File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/chromium/webdriver.py", line 66, in __init__
super().__init__(command_executor=executor, options=options)
File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/remote/webdriver.py", line 208, in __init__
self.start_session(capabilities)
File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/remote/webdriver.py", line 292, in start_session
response = self.execute(Command.NEW_SESSION, caps)["value"]
File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/remote/webdriver.py", line 347, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally.
(session not created: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
#0 0x55b34ba06f83 <unknown>
#1 0x55b34b6bfcf7 <unknown>
#2 0x55b34b6f760e <unknown>
#3 0x55b34b6f426e <unknown>
#4 0x55b34b74480c <unknown>
#5 0x55b34b738e53 <unknown>
#5 0x55b34b700dd4 <unknown>
#7 0x55b34b7021de <unknown>
#8 0x55b34b9cb531 <unknown>
#9 0x55b34b9cf455 <unknown>
#10 0x55b34b9b7f55 <unknown>
#11 0x55b34b9d00ef <unknown>
#12 0x55b34b99b99f <unknown>
#13 0x55b34b9f4008 <unknown>
#14 0x55b34b9f41d7 <unknown>
#15 0x55b34ba06124 <unknown>
#16 0x7f961961fea7 start_thread
93号线是
driver = webdriver.Chrome(options=options)
与具有相同代码库的其他爬虫的唯一显着区别:我在运行之前删除了 Chromium 配置文件,但不是这个。
在网上搜索了很多,发现https://github.com/SeleniumHQ/selenium/issues/6049我并不孤单。这是一个非常隐蔽的错误。
在摸索了几个小时后,我终于明白了:
我需要净化我的
--user-data-dir=/path/to/profil_X
,所以:
rm -rf ~/.config/chromium/profil_X
现在脚本正在无缝运行