如何使用Python在新标签页的Google Chrome中打开URL?

问题描述 投票:0回答:1

我正在使用以下代码打开新的chrome浏览器窗口。运行代码时,它总是在现有标签中打开一个新页面。

import webbrowser
import pyautogui

url = 'google.com'
chrome_path = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(chrome_path))
webbrowser.get('chrome').open_new(url)

print(pyautogui.position())

有人可以建议如何打开一个新标签页吗?

google-chrome pyautogui python-webbrowser
1个回答
0
投票

应该很简单:

    webbrowser.get('chrome').open_new_tab(url)

在文档中说:

webbrowser.open_new_tab(url):如果可能,在默认浏览器的新页面(“ tab”)中打开url,否则等效于open_new()。

仅供参考:

webbrowser.open_new(url):如果可能,在默认浏览器的新窗口中打开url,否则,在唯一的浏览器窗口中打开url。

© www.soinside.com 2019 - 2024. All rights reserved.