簡體   English   中英

Web瀏覽器chrome,在新的window中打不開URL,一直以tab打開URL

[英]Web browser chrome, can't open URL in new window, keeps opening URL as a tab

我正在嘗試在新的 window 中打開一個 URL。我無法使用 selenium,因為它不會登錄 Google。

我的默認瀏覽器是使用 Windows 10 的 Chrome,我已經打開了 3 個 Chrome windows,每個瀏覽器都帶有多個選項卡。

這是我在 Python 3.6 上的代碼:

import webbrowser

url = 'https://google.com'

open_google = webbrowser.open('https://google.com', new=1)
open_google = webbrowser.open_new('https://google.com')

這兩個都在我當前的 window 中為我提供了一個新選項卡,而不是新的 window。為什么會這樣? 它是Chrome中的設置嗎?

如何使用 os.system 或子進程打開一個新的 window,然后使用 webbrowser 獲取 URL/應用程序以在那里打開。

就像是:

import subprocess
command = "cmd /c start chrome http://www.google.com --new-window"
subprocess.Popen(command, shell=True)

然后做:

open_google = webbrowser.open('https://google.com', new=1)

我希望能夠啟動不同的瀏覽器,因為它們具有不同的默認主題並且它們的顯示在我的計算機上看起來不同。

這是一種將 URL 字符串參數化以動態創建瀏覽器名稱為“動態”的 URL 的方法。

import subprocess

browser_type = "chrome"  # Replace the value with "edge" or "firefox"

location_url = "https://stackoverflow.com/questions/7521729/how-to-open-a-new-default-browser-window-in-python-when-the-default-is-{browser_type}"

command_fstring = f"cmd /c start firefox {location_url} --new-window"

subprocess.Popen(command_string, shell=True)

值得稱贊的是,這是基於@Sharath 在此頁面上的回答: Web 瀏覽器 chrome,無法在新的 window 中打開 URL,繼續將 URL 作為選項卡打開

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM