Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help wth web page question
#1
Hi all

I am using python 2 on a Raspberry Pi microcomputer.

What I am trying to achieve is fairly straightforward. I have a URL which is stored in a string called A. First I want to open a web page using A as the url. That is easy to do.

import webbrowser

webbrowser.open(A)

Now after a minute or so A changes so I want to close down my browser window and then open up a new browser window using A again.

The problem is that I can't find a command to close the browser window. Solutions I have seen suggest using the kill function and also selenium but all the scripts I have tried result in errors.

Can someone please help with a simple solution that opens and closes a browser window with a web page in it? 

Thanks for your patience

Peter
Reply
#2
There are loads of way to close a browser window. You could use selenium, pynput, subproccess.

Here is my solution using pynput, assuming that you are currently on the page you want to close

from pynput.keyboard import Key, Controller

keyboard = Controller()
keyboard.press(Key.ctrl)
keyboard.press("w")
keyboard.release(Key.ctrl)
keyboard.release("w")
There are many different solutions to this though and if this doesn't help you could post more in detail what you are trying to do and what errors you are getting.
Reply
#3
Thanks

With respect to your solution, I don't want any user input from a keyboard or elsewhere. basically what is happening is this. I have a small radio receiving device that is receiving the frequency of a radio station periodically sent from another microcontroller. This frequency will be put in a variable 'A'.
The program takes the frequency in A and loads a webpage showing radio stations on that frequency. The frequency is part of the url.

So what I need to do is load the webpage and periodically check the variable A. When A changes then the web page needs to be closed down and a new web page loaded.

I can load the webpage using

import webbrowser

webbrowser.open(A)

but I need a quick and simple way to close it down to I can load another web page.

cheers Peter

Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  use Xpath in Python :: libxml2 for a page-to-page skip-setting apollo 2 3,618 Mar-19-2020, 06:13 PM
Last Post: apollo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020