0

I am trying to make a Python script that simply kicks me off of facebook after 10 minutes, any ideas on the best way to either terminate the browser or even better URL opened specifically?

#Stay on facebook for 10 minute session

import time
import webbrowser
import sys

webbrowser.open("http://www.facebook.com/")

time.sleep(600)
#terminate session here
sys.exit()

Thanks for the help!

1 Answers1

1

You'd open the URL, determine what browser is was opened with, then kill it (via os.kill or similar).

Not sure how to do it with the webbrowser module, but since I guess you're not distributing the script, you could instead open a hardcoded browser via subprocess, e.g Firefox:

import time
import subprocess

p = subprocess.Popen(["firefox", "http://www.facebook.com"])
time.sleep(600)
p.kill()
dbr
  • 165,801
  • 69
  • 278
  • 343
  • Thanks dbr,that seems to work, but there is only one problem that I still see. When I use the script by itself and the browser is not already opened it works, but if I had my browser open already, it will only open the URL, and not close it. I am using Chromium if that matters, but I assume it would be the same across all browsers, any suggestions? –  Nov 02 '12 at 04:27
  • @Andy093 Hmm, when Chromium is running, the `chromium` command must just tell the main process to open a new tab, then exit. I'm not sure how to do this without just murdering all the Chrome processes [like this](http://stackoverflow.com/questions/2940858/kill-process-by-name-in-python) – dbr Nov 02 '12 at 07:46