如何在mac osx上通过python代码打开一个url

时间:2013-10-20 07:01:16

标签: python macos python-webbrowser

我想通过mac osx上的python代码打开一个url。我正在使用safari。我尝试了webbrowser.open(url,new=1,autoraise=True)webbrowser.open(url)webbrowser.open_new(url)webbrowser.open_new_tab(url)。有时,如果已打开四个五个选项卡,则会打开一个新选项卡,有时则不会打开。我想让它适用于所有浏览器,如safari,chrome等。

1 个答案:

答案 0 :(得分:0)

要在上一个答案中添加内容...我有同样的问题,但想在Google Chrome中打开本地(SVG)文件。 我找到的解决方案(here)是

    if platform == "darwin":  # check if on OSX
        file_location = "file:///" + file_location
    webbrowser.get().open(file_location, new=new)

这适用于OSX 10.10.4。