Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python webbrowser保持google的开放性?_Python_Python 3.x_Google Chrome_Python Webbrowser - Fatal编程技术网

如何使用Python webbrowser保持google的开放性?

如何使用Python webbrowser保持google的开放性?,python,python-3.x,google-chrome,python-webbrowser,Python,Python 3.x,Google Chrome,Python Webbrowser,我试图通过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" webbr

我试图通过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')

你也可以走了。

不过对我来说还没有结束。你的chrome可能会因为其他错误而崩溃。它显示了同样的东西——在打开所有标签后,chrome会自动关闭。然后你必须做一些QA工作。就像在任何其他浏览器上尝试一样,重新启动系统,清除缓存等等,因为这段代码(你的也一样)在我尝试的任何地方都可以正常工作。