harveyD harveyD - 1 year ago 94
Python Question

Opening tabs using Webbrowser module in Python

I'm writing a Python Script using webbrowser module to automatically open the desired webpages.

The issue I'm facing is that I'm only able to open the webpages on different Browser windows and not on the same Browser window on different tabs.

Below is the code that I'm using.

#! /usr/bin/python -tt

import webbrowser

def main():

if __name__ == '__main__':

I want to open all these links on the same web browser window on separate tabs and not on different browser windows.
Thanks :)

Answer Source

You need to use webbrowser.open_new_tab(url). For example...

import webbrowser
url = 'http://www.stackoverflow.com'
url2 = 'http://www.stackexchange.com'

def main():
    webbrowser.open(url2) # To open new window
    print('Opening Stack Exchange website!')
    webbrowser.open_new_tab(url) # To open in new tab
    print('Opening Stack Overflow website in a new tab!')

if __name__ == '__main__':

Oops Vasily beat me to it :P