4

I've seen a few questions related to this, but I'm still having trouble.

Running the code:

>>>webbrowser.get('firefox')

errors with:

webbrowser.Error: could not locate runnable browser

To troubleshoot I ran:

>>>print(webbrowser._browser)

{'windows-default': [<class 'webbrowser.WindowsDefault'>, None], 'c:\\program files\\internet explorer\\iexplorer.exe': [None, <webbrowser.BackgroundBrowser object at 0x000000000651FEB8>]}

The odd thing is that I have Firefox installed, it is my default browser, and the HTML file I'm trying to opens through Python, opens with Firefox.

All would be right with the world except I need to send this program out to people who likely have IE set as their Windows default, and the HTML file has to be opened in Firefox.

RussellB.
  • 346
  • 1
  • 3
  • 9

3 Answers3

1

All would be right with the world except I need to send this program out to people who likely have IE set as their Windows default, and the HTML file has to be opened in Firefox.

One way to solve it is to use the selenium browser automation package. You can open local HTML files with that as well:

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("file:///D:/folder/abcd.html")
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • I'll give that a try. Complicating issues a bit more, all the users are on a company network with the base installation of Python 3.5. Do you have any suggestions when using the standard library? – RussellB. Jun 20 '16 at 20:27
  • @RussellB. `selenium` would probably be the most reliable option. But, you can open browsers in custom paths with `webbrowser` - example for chrome: http://stackoverflow.com/questions/22445217/python-webbrowser-open-to-open-chrome-browser. Also see http://stackoverflow.com/questions/5916270/pythons-webbrowser-launches-ie-instead-of-default-on-windows-7. – alecxe Jun 20 '16 at 23:45
  • @RussellB. `virtualenv` – JakeD Jun 09 '17 at 01:37
1

Add %s to the end of the path to open it by Firefox.

webbrowser.get('C:/Program Files (x86)/Mozilla Firefox/firefox.exe %s')
Louis Yang
  • 3,511
  • 1
  • 25
  • 24
0

Add these two lines at top to register firefox

firefox_path="C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"

this will locate your firefox executable

webbrowser.register('firefox', None,webbrowser.BackgroundBrowser(firefox_path))

Then try:

webbrowser.get('firefox') 

this worked for me in both python2 and python3

sangwan9
  • 1
  • 1