views:

168

answers:

1

Hi, I want to create a MSWindows Python program that would launch a new Firefox window with multiple tabs each time it is run. For example if I want to search "hello", a new window pops out (even if a Firefox window is already open) and then launches a Google and Bing tabs searching for "hello". If I change the keyword to "world", a new browser pops out again with Google and Bing tabs searching for "world".

I've looked at the webbrowser module but couldn't get it to: 1. Launch a new browser when a browser is already open: e.g. webbrowser.open('http://www.google.com',new=1) will instead open a new tab 2. Launch multiple tabs simultaneously in the same window

Appreciate the help.

Thanks.

+1  A: 

webbrowser just doesn't give you this degree of control. Use subprocess instead, to explicitly launch firefox with a new window and then add tabs to it. The firefox command line arguments reference is here, but, briefly, what you want is one firefox.exe -new-window <url> (using the URL you want in lieu of <url> of course), then one or more firefox.exe -new-tab <url> (ditto). You may also want to control width and height, use a different profile from the default one, etc -- the command-line arguments let you do all that.

Alex Martelli
Thanks Alex! It worked!
newbie py
@newbie, on SO, "thanks are silver, accepts are gold" -- if my answer has solved your problem, why not accept it (using the checkmark-shaped icon under the number of votes you can see at the left of the answer)?-)
Alex Martelli