如何使用 Web 浏览器从 Python 脚本启动 Microsoft Edge

Kay*_*199 7 python python-webbrowser

使用webbrowser lib,我可以从 python 脚本启动 Chrome 和 Firefox。Edge 则失败了。我注意到使用webdriver启动 Edge 的方法,但我的问题是是否可以使用以下脚本来启动 Edge。目前它仅启动 Chrome。

import webbrowser

chrome_path="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
edge_path="C:\Windows\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe"

webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(chrome_path))
webbrowser.register('edge', None, webbrowser.BackgroundBrowser(edge_path))

webbrowser.get('chrome').open('http://www.google.com')
webbrowser.get('edge').open('http://www.microsoft.com')
Run Code Online (Sandbox Code Playgroud)

小智 10

无法代表您的 Windows 版本,但在最新版本中,边缘文件路径是

C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe