使用Python在Firefox(win)选项卡上启动网页 [英] Launch a webpage on a Firefox (win) tab using Python
本文介绍了使用Python在Firefox(win)选项卡上启动网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用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:
方法1 :
os.system('C:\Program Files\Mozilla Firefox\Firefox.exe -new-tab http://www.google.com/');
和方法2:
os.startfile('C:\Program Files\Mozilla Firefox\Firefox.exe -new-tab http://www.google.com/');
如果不添加参数(-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.
推荐答案
您需要使用 webbrowser
模块
You need to use the webbrowser
module
import webbrowser
webbrowser.open('http://www.google.com')
[编辑]
如果您要在非默认浏览器中打开网址,请尝试:
If you want to open a url in a non-default browser try:
webbrowser.get('firefox').open_new_tab('http://www.google.com')
这篇关于使用Python在Firefox(win)选项卡上启动网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文