Codeman
Codeman

Reputation: 507

How to keep google open using Python webbrowser?

I'm trying to open several google pages through python webbrowser, and I've gotten it to work, but after opening all the pages, google simply closes unless I manually click it. Why is this happening? Help is appreciated, and thank in advance.

import pyautogui as py
import keyboard as key
import time

chrome_path="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
webbrowser.register('chrome',None, webbrowser.BackgroundBrowser(chrome_path))


def n_t():
    py.hotkey('ctrl', 't')

def m_t():
    py.hotkey('ctrl', 'tab')

def gogle():
    webbrowser.get('chrome').open('gmail.com')
    py.press('enter')
    time.sleep(5)
    n_t()
    py.write('www.youtube.com')
    py.press('enter')
    n_t()
    py.write('hangouts.google.com/authuser=2')
    py.press('enter')
    n_t()
    py.write('stackoverflow.com')
    py.press('enter')
    m_t()

gogle()

Upvotes: 0

Views: 147

Answers (1)

Shrey
Shrey

Reputation: 416

Use this:

import webbrowser
webbrowser.open('https://google.com')
webbrowser.open('https://gmail.com')
webbrowser.open('https://youtube.com')
webbrowser.open('https://stackoverflow.com')

and you're good to go.

Upvotes: 1

Related Questions