Python Forum

Full Version: webbrowser open multiple sites incognito
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The following code opens all the pages in a single browser, in tabs, in one go.
i would like to have it incognito. here is my working code:
import webbrowser 

# URL list
webbrowser.open("https://edition.cnn.com/", new=0)
webbrowser.open('https://www.yahoo.com/, new=2)
webbrowser.open('https://www.bloomberg.com', new=2)
webbrowser.open("https://www.iefimerida.gr", new=2)
webbrowser.open('https://slashdot.org/', new=2)
webbrowser.open('https://www.python.org/', new=2)
webbrowser.open('http://youtube.com', new=2)


# Windows path 
chrome_path = r"c:\Program Files\Google\Chrome\Application\chrome.exe"

# Register the browser 
webbrowser.register('chrome', None, 
					webbrowser.BackgroundBrowser(chrome_path)) 

# Call it  
webbrowser.get('chrome').open(url) 
i have tried to add to the --incognito after the chrome.exe
# Windows path 
chrome_path = r"c:\Program Files\Google\Chrome\Application\chrome.exe" %s --incognito"
without success.

what am i missing?
I rarely use MS windows, but the examples that I find include (x86) in the path.
The C: is also capitalized, but I seem to recall that is not an issue with MS windows
chrome_path = "C:\Program Files Program Files (x86)\Google\Chrome\Application\chrome.exe" %s --incognito"
no no, the path i have is correct. Also, if you check the above code (without incognito) is without x86 and it works.
even though i added x86 as you suggested, nothing works. So the is ok. But why i cannot get it to work incognito? ALso i have tried it in GNU/Linux and i have the same results.

OK, let's ignore the MS windows. Does it work in your environment? if yes, what is your environment and what code did you use?
Here i working test,had to use subprocess to get incognito to work.
import subprocess

chrome_path = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
url_list = [
    "https://python-forum.io/",
    "https://www.python.org/"
]
args = [chrome_path, '--incognito'] + url_list
try:
    subprocess.Popen(args)
except Exception as e:
    print(f"An error occurred: {e}")
It works. Thanks a lot! Dance