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

2020-05-25 17:42发布

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.

9条回答
The star\"
2楼-- · 2020-05-25 18:34

you can use Mozilla class in webbrowser:

import webbrowser
firefox = webbrowser.Mozilla("C:\\Program Files\\Mozilla Firefox\\firefox.exe")
firefox.open('http://www.google.com')
查看更多
神经病院院长
3楼-- · 2020-05-25 18:35

Use os.startfile() passing only the url. This will cause the URL to be opened in a new tab/window in the user's default browser, which is much nicer to your user.

查看更多
Anthone
4楼-- · 2020-05-25 18:35

opening a link without internet explorer and use firefox, just make sure firefox is the default web browser.

import webbrowser


http = 'http://'
links = input()
b = webbrowser.open_new(http + links)
查看更多
登录 后发表回答