如何使用Python网络浏览器保持Google开放?

问题描述

我正在尝试通过python webbrowser打开多个Google页面,并且已经可以使用,但是在打开所有页面后,除非我手动单击,否则Google会关闭。为什么会这样呢?感谢您的帮助,在此先感谢。

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()

解决方法

使用此:

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

您很高兴。