I'm trying to write a Python script to open a URL, but I keep getting errors when I try to use it:
import webbrowser
firefox = webbrowser.get('mozilla')
This is the error:
Traceback (most recent call last):
File "C:\Users\Gelu\Documents\CSCI\Image URL Generator\src\Generator.py", line 8, in <module>
firefox = webbrowser.get('mozilla')
File "C:\Program Files\Python31\lib\webbrowser.py", line 53, in get
raise Error("could not locate runnable browser")
webbrowser.Error: could not locate runnable browser
Any ideas why this isn't working?
Mozilla.org is UP and reachable by us.
For me the issue was, webbrowser.py did not recognize any other browser in my windows machine. So, i had to register the browser and then launch a new tab.
import webbrowser
urL='https://www.google.com'
firefox_path="C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"
webbrowser.register('firefox', None,webbrowser.BackgroundBrowser(firefox_path),1)
webbrowser.get('firefox').open_new_tab(urL)
Hope this helps some one.
Also some python notes for reference on what register does ,
webbrowser.register(name, constructor[, instance])¶
Register the browser type name. Once a browser type is registered, the get() function can return a controller for that browser type. If instance is not provided, or is None, constructor will be called without parameters to create an instance when needed. If instance is provided, constructor will never be called, and may be None.This entry point is only useful if you plan to either set the BROWSER variable or call get() with a nonempty argument matching the name of a handler you declare.
if you do
import webbrowser
print webbrowser._browsers
you will get a list of the recognized browsers on your system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With