Question

I am trying to have this program open a tab, wait for 15 seconds, then quit Chrome and reopen the tab immediately. Right now, it opens a tab, waits for 15 seconds then closes Chrome and waits for another 15 seconds before reopening it. How would I correct this loop? I'm pretty new to python so any help would be greatly appreciated.

#!/usr/bin/python

import webbrowser
from time import sleep
import os

a=0

while True:
    webbrowser.open_new("http://google.com")
    sleep(15)
    os.system("killall 'Google Chrome'")
    a=a+0
Was it helpful?

Solution

I found that if I just use open_new the kill task does not work (for unknown reasons), but if I use open_new_tab this seems to work, although it struggles when trying to reopen, so a short sleep after the kill may be helpful (even if only 1 second).

Also I can't help but notice that you are adding zero to a each time through the loop is this meant to be +1?

OTHER TIPS

simply add sleep(15) at the end of the loop

while True:
    webbrowser.open_new("http://google.com")
    sleep(15)
    os.system("killall 'Google Chrome'")
    a=a+0
    sleep(15)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top