Mr Discognito
Mr Discognito

Reputation: 1

How do you close Python webbrowser in Rasbian?

I'm writing a python 3 viewbot which is to run on a rasberry pi, and I need to find a way to close the webbrowser (which is chromium in rasbian)

I have already tried 'webbrowser.close()', but it didn't work.

The expected result is the program opening up whatever url you give it, then closing it after 6 seconds. This should happen the desired amount of times. Currently, it opens the link the desired amount of times, but it doesn't close the webbrowser after opening a link. All help is highly appreciated.

Here is the code for the viewbot in python 3:


```import time



```url = input("url")

```a = int(input("quant"))

```for i in range(a):

```   webbrowser.open(url)

```    time.sleep(6) #depends on internet speed

```    ##need some code here to close the webbrowser.##






Upvotes: 0

Views: 673

Answers (1)

akash
akash

Reputation: 793

Use a python selenium webdriver or use process handle that means find the pid of the browser and kill them.

Using selenium:

from selenium import webdriver
from time import sleep

driver = webdriver.chromium()  # change it as a required browser name 
driver.get("http://www.google.com")
sleep(6)
driver.close()

Process handle:

import time
import subprocess

p = subprocess.Popen(["chromium", "http://www.google.com"])
time.sleep(6)
p.kill()

I doubt this'll work in in chromium browser, so try to use Firefox if possible.

Upvotes: 1

Related Questions