Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch a webpage on a Firefox (win) tab using Python

I'm trying to launch a website url in a new tab using python in that way, but it didn't worked in these both ways:

Method 1:

os.system('C:\Program Files\Mozilla Firefox\Firefox.exe -new-tab http://www.google.com/');

and Method 2:

os.startfile('C:\Program Files\Mozilla Firefox\Firefox.exe -new-tab http://www.google.com/');

If I don't add the parameters (-new-tab http://www.google.com/) it works, opening the default page.

like image 415
Leandro Ardissone Avatar asked Sep 06 '25 12:09

Leandro Ardissone


2 Answers

You need to use the webbrowser module

import webbrowser
webbrowser.open('http://www.google.com')

[edit]

If you want to open a url in a non-default browser try:

webbrowser.get('firefox').open_new_tab('http://www.google.com')
like image 181
Nadia Alramli Avatar answered Sep 08 '25 02:09

Nadia Alramli


If you want to start a program with parameters the subprocess module is a better fit:

import subprocess
subprocess.call([r'C:\Program Files\Mozilla Firefox\Firefox.exe',
    '-new-tab', 'http://www.google.com/'])
like image 44
sth Avatar answered Sep 08 '25 01:09

sth