Web browser module in python

Hi,

I am trying to multiple urls in multiple tabs within a browser window.
I am using webbrowser module in python:
My code:

import webbrowser

li = ['http://unix.com','http://google.com','http://yahoo.com']
for url in li:
  webbrowser.open_new_tab(url)

This code works fine, if the browser is already opened.
If the browser is not started yet, then the code opens three new windows of the browser which i don;t want. How to control it to open within a browser window?

Thanks in advance.

Thanks,
Pandeeswaran

Opening a new tab pretty much suggests that a browser instance is already running. Perhaps opening an initial browser instance and then the tabs would work better.

import webbrowser
webbrowser.open_new('http://somesite.com')
li = ['http://unix.com','http://google.com','http://yahoo.com']
for url in li:
  webbrowser.open_new_tab(url)

Thanks for your response.
i have tried the solution which you suggested. But that results in 4 browser windows and doesn't address the problem i mentioned.
SOo, all here needed is, opening a browser instance and wait until that instance opens completely.Then we need to invoke the other urls and so that they can open in the same window.

Any idea how to check that?

Thanks

I tested on both Windows and Linux. Perhaps check you're default browser settings and make they're set to open a new tab and not a new window.

But what i am wondering is , if the browser instance is already opened, then this code works as expected.

Thanks,
Pandeeswaran

From the webbrowser module documentation.

webbrowser.open_new_tab(url)

Open url in a new page (�tab�) of the default browser, if possible, otherwise equivalent to open_new().

So if the browser is already running it will open a tab. Otherwise, it will revert to open_new, which opens a new window.

webbrowser.open_new(url)

Open url in a new window of the default browser, if possible, otherwise, open url in the only browser window.