Opening a URL with Different Browsers
suggest changeThe webbrowser module also supports different browsers using the register() and get() methods. The get method is used to create a browser controller using a specific executable’s path and the register method is used to attach these executables to preset browser types for future use, commonly when multiple browser types are used.
import webbrowser
ff_path = webbrowser.get("C:/Program Files/Mozilla Firefox/firefox.exe")
ff = webbrowser.get(ff_path)
ff.open("http://stackoverflow.com/")
get splits that argument on spaces and looks for a known browser basename. The first token here is C:/Program, so get raises webbrowser.Error before the second get call. get expects a browser name or a command string, not a controller object.
Registering a browser type:
import webbrowser
ff_path = webbrowser.get("C:/Program Files/Mozilla Firefox/firefox.exe")
ff = webbrowser.get(ff_path)
webbrowser.register('firefox', None, ff)
# To use Firefox later, you can use this
webbrowser.get('firefox').open("https://stackoverflow.com/")
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents