我尝试通过添加如下代码片段来指定用户数据目录和配置文件以连接到Chrome,但无法成功:
options.add_argument('--user-data-dir={}'.format(user_data_dir))
options.add_argument('--profile-dir={}'.format(profile_dir))
在不使用这些选项的情况下,程序可以正常运行。为解决这个问题,我还尝试添加了一些额外的参数:
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument("--disable-gpu")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")
尽管如此,我在相关论坛上并没有找到关于此问题的具体解决方案。
遇到的错误信息如下:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally.
(session not created: DevToolsActivePort file doesn't exist)
(启动自C:\Program Files\Google\Chrome\Application\chrome.exe的进程已不再运行,因此ChromeDriver认为Chrome已崩溃。)
Stacktrace:
GetHandleVerifier [0x00B26EE3+174339]
(No symbol) [0x00A50A51]
(No symbol) [0x00766FF6]
(No symbol) [0x0078A756]
(No symbol) [0x00787A0F]
(No symbol) [0x007BE259]
(No symbol) [0x007BDBBA]
(No symbol) [0x007B6DA6]
(No symbol) [0x00791034]
(No symbol) [0x00791F8D]
GetHandleVerifier [0x00BC4B1C+820540]
sqlite3_dbdata_init [0x00C853EE+653550]
sqlite3_dbdata_init [0x00C84E09+652041]
sqlite3_dbdata_init [0x00C797CC+605388]
sqlite3_dbdata_init [0x00C85D9B+656027]
(No symbol) [0x00A5FE6C]
(No symbol) [0x00A583B8]
(No symbol) [0x00A584DD]
(No symbol) [0x00A45818]
BaseThreadInitThunk [0x76457BA9+25]
RtlInitializeExceptionChain [0x77AABD2B+107]
RtlClearBits [0x77AABCAF+191]