Launch Firefox with Python 3.x -


i'm trying write script launch firefox me, open google in new tab, , able search (for instance, www.espn.com). i'm trying achieve using webbrowser module, run error each time try launching firefox script. also, firefox not default browser.

import webbrowser webbrowser.get('firefox').open_new_tab('http://www.google.com') 

whenever run following error:

traceback (most recent call last):   file "c:/python33/test bing.py", line 6, in <module>     webbrowser.get('firefox').open_new_tab('http://www.google.com')   file "c:\python33\lib\webbrowser.py", line 53, in     raise error("could not locate runnable browser") webbrowser.error: not locate runnable browser 

i'm unsure why script struggling locate firefox.exe have tried specifying in 'firefox' actual location of firefox.exe in c: still same error.

i'm sure there's small error in code can't see, if point out i'm doing wrong i'd appreciate it!

i have firefox installed on windows machine well, , have same error.

if run following 2 lines in idle:

import webbrowser print webbrowser._browsers # or print(webbrowser._browsers) python 3.x 

then you'll dict of available browser controllers, said in source code. on system prints:

{'windows-default': [<class 'webbrowser.windowsdefault'>, none],      'c:\\program files\\internet explorer\\iexplore.exe': [none, <webbrowser.backgroundbrowser object @ 0x01baf6b0>] } 

i think it's worth noting have ie, chrome , firefox on computer , looks "default" , "internet explorer" given here. according the documentation, keys 'firefox' , 'mozilla' should work, of course not.

going source code, in line 539 563, looks python register browser if corresponding (hard-coded) key (e.g. 'firefox' or 'chrome') considered command (using _iscommand(cmd) line 121.

i closed idle , added firefox path %path% , found after restarting idle, _iscommand('firefox') returns true , webbrowser.get('firefox) returns <webbrowser.backgroundbrowser object @ 0x01bdf7f0>. however, webbrowser._iscommand("chrome") still returns false , webbrowser.get("chrome") still throws aforementioned exception.

my conclusion unless webbrowser module changes not rely on %path% (at least on windows), you'll have add firefox path %path% variable first, or make assumption firefox default browser.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -