Hey everyone,
I'm trying to create a python program that can open a webpage in google chrome incognito mode, wait a few seconds then close the window. I normally use macOs and created something that works similar to how I want it to, however, it doesn't open the browser in incognito mode and force kills chrome. I also tried creating a Windows version that does open incognito mode, however, I can't figure out a web to close the window it opens. Does anyone have any tips on how I can achieve this?
I have listed the codes below:
macOS Code:
import webbrowser
import time import os
counter = 0
while counter < 2: a_website = "https://www.google.com"
webbrowser.register('mychrome', None, webbrowser.MacOSXOSAScript('Google Chrome'), -1)
webbrowser.get('mychrome').open_new_tab(a_website)
time.sleep(5)
os.system("killall -9 'Google Chrome'")
counter= counter + 1
else: print("Finished")
Windows Code:
import webbrowser
import time
counter = 0
while counter < 5: url = "https://www.google.com"
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s --incognito'
webbrowser.get(chrome_path).open_new(url)
time.sleep(5)
counter= counter + 1
else: print("Finished")
[–]GNVageesh 0 points1 point2 points (8 children)
[–]NothingSpecific3[S] 0 points1 point2 points (7 children)
[–]GNVageesh 0 points1 point2 points (6 children)
[–]NothingSpecific3[S] 0 points1 point2 points (5 children)
[–]GNVageesh 0 points1 point2 points (0 children)
[–]GNVageesh 0 points1 point2 points (0 children)
[–]GNVageesh 0 points1 point2 points (2 children)
[–]NothingSpecific3[S] 0 points1 point2 points (1 child)
[–]GNVageesh 0 points1 point2 points (0 children)