Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
webbrowser
#1
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)
Reply
#2
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.
Reply
#3
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.
Reply
#4
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]
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  webbrowser not working in screen management in kivy thousif 1 1,875 Nov-25-2020, 04:02 PM
Last Post: Axel_Erfurt
  Python - control a webbrowser ARGMER 1 3,419 Oct-26-2018, 06:20 PM
Last Post: metulburr
  Selenium webbrowser send entern and escape key pythongeekme 0 4,082 Jul-20-2017, 08:31 PM
Last Post: pythongeekme

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020