1

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
Nick
  • 13
  • 1
  • 4

2 Answers2

1

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?

ChrisProsser
  • 12,598
  • 6
  • 35
  • 44
  • Thank you so much that solved it! Once I get 15 rep I'll come back and rep you. Thanks for your help. – Nick Jul 07 '13 at 16:44
-1

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)
DevZer0
  • 13,433
  • 7
  • 27
  • 51
  • I'm trying to not have it sleep again once it quits Chrome. I would like it to immediately reopen the tab. How would I do that? Thanks for your help. – Nick Jul 07 '13 at 16:40