带有Firefox的Mac上的webbrowser.get(“firefox”)找不到可运行的浏览器“ [英] webbrowser.get("firefox") on a Mac with Firefox "could not locate runnable browser"

查看:625
本文介绍了带有Firefox的Mac上的webbrowser.get(“firefox”)找不到可运行的浏览器“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我需要的是知道运行哪个魔术命令行或OSA脚本程序来启动现有Firefox浏览器中的URL(如果正在运行)或者如果启动Firefox 。在Mac上。



我正在测试一个Python程序(Crunchy Python),它设置了一个Web服务器,然后使用Firefox作为前端。它使用以下方式启动Web应用程序:

$ p $ try:
client = webbrowser.get(firefox)
client.open(url)
返回
除了:
try:
client = webbrowser.get()
client.open(url)
返回
,除了:
print('请在Firefox中打开%s。'%url)

我在我的Mac上使用Safari作为默认设置,但是我也安装并运行了Firefox。上面的代码在Safari中启动了新的URL(在本地主机上)。脆脆在Safari中不能正常工作。我想在Firefox中看到它,因为我有Firefox。在Python 2.5,2.6和2.7(从版本控制)下,我得到这个:

 >>> import webbrowser 
>>> webbrowser.get(firefox)
Traceback(最近一次调用的最后一个):
在< module>文件中的< stdin>
文件/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/webbrowser.py,第46行,得到
raise错误(找不到可运行的浏览器)
webbrowser.Error:找不到可运行的浏览器

Firefox在那里。我尝试使用webbrowser.get(/ Applications / Firefox.app / Contents / MacOS / firefox%s)启动一个新的Firefox实例,然后抱怨Firefox的另一个实例已经在运行。



我真的希望webbrowser在Firefox的现有选项卡/窗口中打开URL,如果它已经在运行,或者在新的Firefox尚未运行。

我查看了webbrowser.py,看起来MacOSX没有firefox支持。没关系,我可以补充一点。但我不知道如何以我想要的方式在Firefox中打开网址。

想法?现在,我可以强制Crunchy给我的URL,我可以手动粘贴到Firefox。

你应该使用启动服务以打开URL。您可以使用 LaunchServices 模块,或使用Apple的打开的工具,或使用启动实用程序(此处):



open 可能是最简单的:

 %open -b org.mozilla.firefox http://www.stackoverflow.com/ 

(或者当然,在Python中与 subprocess 或类似的等价物)应该做你想做的事。


I think what I need here is to know which magic command-line or OSA script program to run to start up a URL in an existing Firefox browser, if one is running, or to also start up Firefox if it isn't. On Mac.

I'm testing a Python program (Crunchy Python) which sets up a web server then uses Firefox for the front end. It starts the web application with the following:

try:
    client = webbrowser.get("firefox")
    client.open(url)
    return
except:
    try:
        client = webbrowser.get()
        client.open(url)
        return
    except:
        print('Please open %s in Firefox.' % url)

I have Safari on my Mac as the default, but I also have Firefox installed and running. The above code started the new URL (on localhost) in Safari. Crunchy does not work well in Safari. I want to see it in Firefox, since I do have Firefox. Under Python 2.5, 2.6, and 2.7 (from version control) I get this:

>>> import webbrowser
>>> webbrowser.get("firefox")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/webbrowser.py", line 46, in get
    raise Error("could not locate runnable browser")
webbrowser.Error: could not locate runnable browser

Firefox is there. I tried using webbrowser.get("/Applications/Firefox.app/Contents/MacOS/firefox %s") which starts up a new instance of Firefox then complains that another instance of Firefox is already running.

I really would like webbrowser to open up the URL in an existing tab/window of Firefox, if it's already running, or in a new Firefox is not already running.

I looked at webbrowser.py and it looks like there is no 'firefox' support for MacOSX. That's okay, I can add that. But I don't know how to open the URL in Firefox in the way I want to.

Ideas? And for now, I can force Crunchy to give me the URL, which I can manually paste into Firefox.

解决方案

You should use Launch Services to open the URL. You can do this with the LaunchServices module, or with Apple's open utility, or with my launch utility (here):

open is probably easiest:

% open -b org.mozilla.firefox http://www.stackoverflow.com/

(or, of course, the equivalent in Python with subprocess or similar) should do what you want.

这篇关于带有Firefox的Mac上的webbrowser.get(“firefox”)找不到可运行的浏览器“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆