How to open a new default browser window in Python

2020-03-14 19:03发布

I have been looking for a way to open a new default browser window from inside Python code.

According to the documentation webbrowser.open_new(url) Should do that. Unfortunately in case Chrome is the default browser it only opens a new tab. Is there any way to open the default browser (without knowing what that browser is)?

4条回答
ゆ 、 Hurt°
2楼-- · 2020-03-14 19:29

I have a feeling it's not Python's fault. Firefox and Chrome (and probably IE) all intercept calls to open new windows and changes them to new tabs. Check the settings in your browser for interpreting those calls.

查看更多
可以哭但决不认输i
3楼-- · 2020-03-14 19:35

Give this a whirl:

import subprocess
command = "cmd /c start chrome http://www.ebay.com --new-window"
subprocess.Popen(command, shell=True)
查看更多
ら.Afraid
4楼-- · 2020-03-14 19:35
import subprocess

def open(url):
    cmd = "open " + url
    print(cmd)
    subprocess.Popen(cmd, shell=True)
查看更多
够拽才男人
5楼-- · 2020-03-14 19:45
webbrowser.open('http://www.google.com', new=1)
查看更多
登录 后发表回答