简体   繁体   中英

How to open new tabs in Firefox from Python or CLI?

I am using CLI way to open Firefox for multiple sites. I am using the following code but it is getting stuck at first site on my 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')

The goal is to open all these sites in tabs at once. The errors I get:

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.

you can try this

firefox --help

output is

......
  --new-window <url> Open <url> in a new window.
  --new-tab <url>    Open <url> in a new tab.
......

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM