如何使用子流程打开新的浏览器选项卡? [英] How can I open a new browser tab with subprocess?

查看:82
本文介绍了如何使用子流程打开新的浏览器选项卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下方法打开新的IE窗口:

I'm opening a new IE window with this:

subprocess.Popen(r'"' + os.environ["PROGRAMFILES"] + 
'\Internet Explorer\IEXPLORE.EXE" ' + Call_URL)

这在关闭IE时很好,但是即使打开它也会产生一个新窗口。如何只打开一个新标签页?如果可能的话,我想使用标准的浏览器-但是我也不知道该怎么做。

This is fine when IE is closed, but even when it's open this spawns a new window. How can I open just a new tab? If possible I'd like to use the standard browser - however I couldn't figure out how to do that either.

注意:我不能使用webbrowser和os没有.startfile。我对os.popen也没有运气(使用Jython 2.5.3b1)。

Note: I can't use webbrowser and os has no .startfile. I had no luck with os.popen either (using Jython 2.5.3b1).

推荐答案

因为您还想要一个标准的浏览器举例说明如何使用chrome打开新标签页。如果尚未打开chrome,它将打开,然后导航到URL。

Since you also wanted a standard browser am giving an example to open a new tab with chrome. If chrome is not open already it will open and then navigate to the URL.

import subprocess
subprocess.Popen("start chrome /new-tab www.google.com",shell = True)

这有效。请尝试让我知道这是否是您想要的。

This works. Please try and let me know if this is what you wanted.

另一种未对Call_URL进行硬编码的

Another one without hardcoding the Call_URL

import subprocess
Call_URL = "www.google.com"
mycmd = r'start chrome /new-tab {}'.format(Call_URL)
subprocess.Popen(mycmd,shell = True) 

您是否期望这样?

这篇关于如何使用子流程打开新的浏览器选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆