Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a url through python code on mac osx

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.

like image 230
user2899498 Avatar asked Jul 22 '26 19:07

user2899498


1 Answers

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.

like image 112
mathandy Avatar answered Jul 25 '26 12:07

mathandy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!