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():
webbrowser.open('url1')
webbrowser.open('url2')
webbrowser.open('url3')
if __name__ == '__main__':
main()
I want to open all these links on the same web browser window on separate tabs and not on different browser windows. Thanks :)
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__':
main()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With