我正在使用以下代码打开新的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())
有人可以建议如何打开一个新标签页吗?
应该很简单:
webbrowser.get('chrome').open_new_tab(url)
在文档中说:
webbrowser.open_new_tab(url):如果可能,在默认浏览器的新页面(“ tab”)中打开url,否则等效于open_new()。
仅供参考:
webbrowser.open_new(url):如果可能,在默认浏览器的新窗口中打开url,否则,在唯一的浏览器窗口中打开url。