0

There are 2 subjects about this issue but all is not for mac.

How can i open a webpage in Incognito mode with Python in my Mac Computer ?

Normal is easy

import webbrowser

webbrowser.open('http://example.com')  # Go to example.com

Some guys this a code like this but this is also now working for mac.

import webbrowser

url = 'http://docs.python.org/'

# MacOS
chrome_path = 'open -a /Applications/Google\ Chrome.app %s'
webbrowser.get(chrome_path).open(url)

Any idea ?

  • There are several solutions here, https://stackoverflow.com/questions/37769148/how-to-open-chrome-in-incognito-mode-from-python have you confirmed that none work on mac? – Hymns For Disco Feb 04 '20 at 14:21
  • @HymnsForDisco yes i have. – onurhanozer Feb 04 '20 at 14:23
  • here are a few answers of commands that should work https://apple.stackexchange.com/questions/306399/open-a-new-chrome-window-in-incognito-mode-from-terminal , you can execute them with the python subprocess module – Hymns For Disco Feb 04 '20 at 14:28
  • I think, if i find chrome path for mac, i can do it, but i can't find it yet. – onurhanozer Feb 04 '20 at 14:31
  • As usual, stack exchange seems to have more answers on this topic. I personally don't have a mac to test but check this out. https://apple.stackexchange.com/questions/95837/find-google-chrome-installation-directory-using-terminal – Hymns For Disco Feb 04 '20 at 14:35
  • is not a easy answer like pc users ? like C:\Documents and Settings\UserName\Local Settings\Application Data\Google\Chrome – onurhanozer Feb 04 '20 at 14:54
  • Unfortunately I'm not a mac user so about the best I could do is google it for you. Hopefully these links have given you the right direction – Hymns For Disco Feb 04 '20 at 14:56
  • Thank you, i made google search, can't find, after i write here, regards – onurhanozer Feb 04 '20 at 15:22

1 Answers1

3

It seems you are using mac OS looking at the patch of your chrome

I also struggled with this one. I ended up using os

import os

os.system("open -na \"Google Chrome\" --args --incognito \"www.google.com\"")