Windows で実行する Firefox ブラウザーを登録しようとしています。Webbrowser のドキュメントによると、「環境変数 BROWSER が存在する場合、ブラウザの os.pathsep で区切られたリストとして、ブラウザのプラットフォームのデフォルト リストを上書きするように解釈され、順番に試行されます」。私は次のものを持っています:
import os
import webbrowser
from subprocess import call
os.environ["BROWSER"] = "C:\\FirefoxPortable\\FirefoxPortable.exe"
webbrowser.open('http://google.com')
これでも iexplorer (デフォルトのブラウザ) が開きます。
また:
>>> webbrowser._browsers
{'windows-default': [<class 'webbrowser.WindowsDefault'>, None], 'c:\\program files\\internet explorer\\iexplore.exe': [None, <webbrowser.BackgroundBrowser object at 0x04A18F90>]}
>>> webbrowser._tryorder
['windows-default', 'C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE']
ここで Firefox を使用するにはどうすればよいですか?
ソース:
# OK, now that we know what the default preference orders for each
# platform are, allow user to override them with the BROWSER variable.
if "BROWSER" in os.environ:
_userchoices = os.environ["BROWSER"].split(os.pathsep)
_userchoices.reverse()
# Treat choices in same way as if passed into get() but do register
# and prepend to _tryorder
for cmdline in _userchoices:
if cmdline != '':
cmd = _synthesize(cmdline, -1)
if cmd[1] is None:
register(cmdline, None, GenericBrowser(cmdline), -1)
cmdline = None # to make del work if _userchoices was empty
del cmdline
del _userchoices
# what to do if _tryorder is now empty?