python - 如何从 Python 或 CLI 在 Firefox 中打开新标签页?
问题描述
我正在使用 CLI 方式为多个站点打开 Firefox。我正在使用以下代码,但它在我的 Mac 上的第一个站点卡住了:
def launch_sites(is_linux=True):
if is_linux:
cmd = 'firefox --new-tab http://adnansiddiqi.me'
push = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
result = push.stdout.read()
result = str(result, 'utf-8')
cmd = 'firefox --new-tab http://google.com'
push = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
result = push.stdout.read()
result = str(result, 'utf-8')
else:
cmd = '/Applications/Firefox.app/Contents/MacOS/firefox-bin http://adnansiddiqi.me'
push = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
result = push.stdout.read()
result = str(result, 'utf-8')
cmd = '/Applications/Firefox.app/Contents/MacOS/firefox-bin http://google.com'
push = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
result = push.stdout.read()
result = str(result, 'utf-8')
目标是一次在选项卡中打开所有这些站点。我得到的错误:
C[GFX1-]: Receive IPC close with reason=AbnormalShutdown
[GFX1-]: Receive IPC close with reason=AbnormalShutdown
Exiting due to channel error.
Exiting due to channel error.
[GFX1-]: Receive IPC close with reason=AbnormalShutdown
[GFX1-]: Receive IPC close with reason=AbnormalShutdown
Exiting due to channel error.
Exiting due to channel error.
解决方案
你可以试试这个
firefox --help
输出是
......
--new-window <url> Open <url> in a new window.
--new-tab <url> Open <url> in a new tab.
......
推荐阅读
- php - PHP Chilkat imap 组件内存泄漏
- eclipse - 在 Eclipse 中保存文件时是否可以自动运行 Junit 测试?
- flutter - 检测何时在 Flutter 中加载布局
- spring-boot - docker容器内的Spring Boot实时重新加载不起作用
- rx-java - 也许在链中完成之后
- html - 如何创建包含来自输入框的用户输入的链接
- html - 使用 CSS 用于所有操作系统的 Sticky Table 两个标头
- pandas - 为什么 SimpleImputer 的 fit_transform 不适用于 google colab 中的数据框?
- nfc - 使用 NFC 避免 Android Beam UI 的设备之间的数据传输
- sharepoint - 分享点列表条件格式输出百分比