? ? ? ? 在上周有一臺服務器重啟之后,Chrome瀏覽器也自動升了級,原本能夠正常使用的自動化辦公程序突然沒法用了,出現了下面的報錯提示。
codes/addCancelBdld.py:980: DeprecationWarning: use options instead of chrome_optionsdriver = webdriver.Chrome(executable_path='./chromedriver.exe', desired_capabilities=desired_capabilities, chrome_options=chrome_options)
[13908:16748:0731/133626.719:ERROR:net\base\network_change_notifier_win.cc:189] WSALookupServiceBegin failed with: 8DevTools remote debugging requires a non-default data directory. Specify this using --user-data-dir.
[6080:23036:0731/133626.876:ERROR:net\base\network_change_notifier_win.cc:189] WSALookupServiceBegin failed with: 8
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
I0000 00:00:1753940192.016375 5356 voice_transcription.cc:58] Registering VoiceTranscriptionCapability
[13908:16748:0731/133643.763:ERROR:components\device_event_log\device_event_log_impl.cc:198] [13:36:43.764] Bluetooth: bluetooth_adapter_winrt.cc:1054 Getting Default Adapter failed.
......
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: DevToolsActivePort file doesn't exist
? ? ? ? 經過多次詢問DeepSeek也未能找到原因,但好在我已經找到了解決方法。
? ? ? ? 我在代碼中指定了--user-data-dir為User Data目錄。這是導致代碼運行時出現上面報錯的罪魁禍首。
chrome_options.add_argument(f"--user-data-dir={os.path.join(os.environ['USERPROFILE'], fr'AppData/Local/Google/Chrome/User Data')}")
? ? ? ? 我將User Data目錄更名為Selenium Data,并將代碼中的--user-data-dir指定為更名后的Selenium Data目錄,代碼就能正常使用了。
? ? ? ? 最后,右鍵桌面上的Chrome快捷方式,點屬性,在目標那一欄的內容后面加上--user-data-dir,也指定為更名后的Selenium Data目錄。
--user-data-dir="%LOCALAPPDATA%\Google\Chrome\Selenium Data"
? ? ? ? 這樣桌面上的Chrome快捷方式也能正常使用了。