1

In python you can open a web browser like this...

import webbrowser
webbrowser.open("stackoverflow.com")

This method opens a new tab EVERY time the page is called. I want to create a web page with text boxes, graphic (SVG) devices, etc... then pass variables to it. Basically... use the browser as a display screen.

The HTML page would reside in the same folder with the python code... so this works just fine...

import webbrowser
webbrowser.open("sample.html")

The issue is... if I place this in a timer that updates every second... I get tab after tab... but what I want is for it to open the page ONCE, then just pass data to it as if I had used a SUBMIT button...

My code would generate the appropriate text... URL plus data... then pass it as a long URL.

webbrowser.open("sample.html?alpha=50&beta=100")

The page would pull the variables "alpha" and "beta", then shove the data into some graphic device using javascript. I have had great success manipulating SVG this way... http://askjerry.info/SVG for example. (Feel free to grab my graphics if you like.)

Is it possible to keep updating a SINGLE page/window instead of a new tab every time??

Thanks, Jerry

Dharman
  • 30,962
  • 25
  • 85
  • 135
Askjerry
  • 49
  • 4
  • Possible duplicate of [Open HTML file in same tab using python script](https://stackoverflow.com/questions/51206588/open-html-file-in-same-tab-using-python-script) – GalAbra Jun 06 '19 at 05:20

2 Answers2

0

Use the selenium module. The .get() method actually just opens the given url in the same tab and leaves the old url. In fact, I think there's even a .refresh().

MegaEmailman
  • 505
  • 3
  • 11
0

From this question: Refresh a local web page using Python

from selenium import webdriver
import time

driver = webdriver.Firefox()

driver.get('URL')
while True:
    time.sleep(20)
    driver.refresh()
driver.quit()

Where you can replace your url and parameters with 'URL' - but if you want to pass data from python to html/javascript you will be better off learning flask or something similar. Then you can update your page using ajax which will make your graphics look nicer and will be tractable if you need to pass more data than just alpha and beta.

sin tribu
  • 318
  • 1
  • 3
  • 8