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.

1
  • 1
    you could install selenium and do webdriver.Firefox() Commented Jun 20, 2016 at 16:44

3 Answers 3

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")
Sign up to request clarification or add additional context in comments.

3 Comments

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. selenium would probably be the most reliable option. But, you can open browsers in custom paths with webbrowser - example for chrome: stackoverflow.com/questions/22445217/…. Also see stackoverflow.com/questions/5916270/….
@RussellB. virtualenv
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')

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.