Mat.C
Mat.C

Reputation: 1429

Python webbroswer open url in same tab

I'm trying to open the broswer and search some urls with the module webbroswer of python, This is my code

import webbrowser

b = webbrowser.get('firefox')
b.open('google.com')
b.open('stackoverflow.com', new=0)

This code works but it opens the urls in two different tabs, i want that it searchs before for google.com and after in the same tab it has to search for stackoverflow.com. I read in the docs that for open a new thab the new parameter has to be set equal to 2 but it is 0 now, why it keeps opening new tabs?

Upvotes: 3

Views: 7905

Answers (3)

user13566659
user13566659

Reputation:

import webbrowser
webbrowser.open('google.com', new = 0)

And the docs says:

If new is 0, the url is opened in the same browser window if possible. If new is 1, a new browser window is opened if possible. If new is 2, a new browser page (“tab”) is opened if possible

The same question has been answered here.

Upvotes: 0

Mike
Mike

Reputation: 80

b.open('stackoverflow.com', new=0)

Your new should be set to 2 not 0.

Upvotes: -1

Ennio Saenz
Ennio Saenz

Reputation: 1

try this: webbrowser.open_new(url) Open url in a new window of the default browser, if possible, otherwise, open url in the only browser window.

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

Upvotes: -1

Related Questions