Lea*_*one 19 python windows command-line
我试图以这种方式使用python在新标签中启动网站网址,但它在这两方面都没有用:
方法1:
os.system('C:\Program Files\Mozilla Firefox\Firefox.exe -new-tab http://www.google.com/');
Run Code Online (Sandbox Code Playgroud)
和方法2:
os.startfile('C:\Program Files\Mozilla Firefox\Firefox.exe -new-tab http://www.google.com/');
Run Code Online (Sandbox Code Playgroud)
如果我不添加参数(-new-tab http://www.google.com/),则可以打开默认页面.
Nad*_*mli 47
您需要使用该webbrowser模块
import webbrowser
webbrowser.open('http://www.google.com')
Run Code Online (Sandbox Code Playgroud)
[ 编辑 ]
如果要在非默认浏览器中打开网址,请尝试:
webbrowser.get('firefox').open_new_tab('http://www.google.com')
Run Code Online (Sandbox Code Playgroud)
sth*_*sth 11
如果要使用参数启动程序,则子进程模块更适合:
import subprocess
subprocess.call([r'C:\Program Files\Mozilla Firefox\Firefox.exe',
'-new-tab', 'http://www.google.com/'])
Run Code Online (Sandbox Code Playgroud)