Close/terminate web browser using Python 3?
Question:
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!
Answers:
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()
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!
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()