3

I want to open a url through python code on mac osx. I am using safari. I tried webbrowser.open(url,new=1,autoraise=True) , webbrowser.open(url), webbrowser.open_new(url), webbrowser.open_new_tab(url). Sometimes, a new tab will open, Sometimes it will not, if already four-five tabs are opened. I want to make it work on all browsers like safari, chrome etc.

3
  • Have you tried the methods outlined here to specify the browser? Commented Oct 20, 2013 at 7:08
  • yes, but I want to open a url by default browser. Suppose, chrome, mozilla is not installed, then it should work with safari. Commented Oct 20, 2013 at 7:41
  • The default is to use the default browser. I think you should post some code where you can reproduce "This one opens as expected" and "this one doesn't". It is impossible to debug when you say it works sometimes. The library is cross platform, so all the examples in the other questions where this has been asked should be relevant. According to one of them chrome will specifically wait until you close a tab that has been opened in this way. Commented Oct 20, 2013 at 7:52

1 Answer 1

5

To add something to the previous answer... I had the same question, but wanted to open a local (SVG) file in Google Chrome. The solution I found (here) was

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

This works for me on OSX 10.10.4.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.