Python Forum

Full Version: webbrowser
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I use python 3.6.2 and need to open different web page in the same tab but it always open in a new tab. Is it possible? Thanks.
import time
import webbrowser
webbrowser.open('https://www.google.com',new=0)
time.sleep(5)
webbrowser.open('http://www.yahoo.com',new=0)
Do you mean to open the two different websites in the same tab, so that yahoo is loaded over google, or is your intention to open both websites in the same window in different tabs?

The new=0 should open the page in the same tab, if possible. I tried modifying the code but coulnd't get it to work. I read this but couldn't find any other explanation other than the new=0 should open the page in the same tab. There might be something hindering it from opening it in the same tab.
I need to open URL1 in a tab and work on it and then open URL2 on the same tab. No more than 1 tab open in browser. I tried Edge or Firefox but no luck.
You might as well just use selenium. It also gives you the option of already having that site open for selenium to get the source, and/or execute actions such as mouse clicks, etc.
import time
from selenium import webdriver
URLS = ("https://www.google.com", "http://www.yahoo.com", "http://www.bing.com")

PATH_TO_DRIVER = '/home/metulburr/chromedriver'
browser = webdriver.Chrome(PATH_TO_DRIVER)
browser.set_window_position(0,0)
for url in URLS:
    browser.get(url)
    time.sleep(5)
[Image: pmMgW2I.gif]