Python Forum
webbrowser open multiple sites incognito
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
webbrowser open multiple sites incognito
#1
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?
Reply
#2
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"
Reply
#3
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?
Reply
#4
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}")
atsitras likes this post
Reply
#5
It works. Thanks a lot! Dance
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020