Python: generic webbrowser.get().open() for chrome.exe does not work

前端 未结 6 1464
天命终不由人
天命终不由人 2020-12-11 09:48

I am on Python 2.7 (Win 8.1 x64) and I want to open a URL in Chrome. As Chrome is only natively supported in 3.3+, I was trying a generic call:

import webbro         


        
6条回答
  •  旧巷少年郎
    2020-12-11 10:19

    On Windows, you don't need to use UNIX-style path. Just wrap the raw string path to google.exe in escaped quotes, and append %s token after it, within an f-string:

    import webbrowser
    
    url = "https://docs.python.org/3/library/webbrowser.html"
    chrome = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
    webbrowser.get(f"\"{chrome}\" %s").open_new_tab(url)
    

提交回复
热议问题