How can I close a web site from a python app?

114 views Asked by At

I have a Linux python app, that runs a web php app on a server, that requests data from a MySql database and saves the answer in a text file on the server. I can download the text file from the server using pysftp however ... I have to manually close the web app. Then I start another python app passing the text file data to it.

I can't find find a way to close the web app using code. I like w3m because it runs from the terminal. I can close it using Shift+Q. I can close with the cap locks on and pushing Q so it doesn't require two keys. But I can't find a way to send Shift+Q programmatically. I have also tried and can run Firefox, and Chrome from python but can't find a way to close them using code in my php app or python app either.

I have tried the obvious:

<?php echo chr(81); ?>
1

There are 1 answers

1
ShunnedJeans On

if your web app is running on a browser:

There is no webbrowser.close, you can use these codes to close the task(in Windows OS):

First Import os package with

import os

then use system function to kill the task

os.system("taskkill /im firefox.exe /f") os.system("taskkill /im chrome.exe /f")

For MacOS, you can use below command:

os.system("killall -9 'Google Chrome'")

source: How to close web browser using python