I\'m using Python to gather some information, construct a very simple html page, save it locally and display the page in my browser using webbrowser.open(\'file:///c:/testfi
The LivePage extension for Chrome. You can write to a file, then LivePage will monitor it for you. You can also optionally refresh on imported content like CSS. Chrome will require that you grant permissions on local file:// urls.
(I'm unaffiliated with the project.)
It looks like several people have asked this in the past but here is a link that sums it up.
Python refresh HTML document
But webbrowser.open( url, new=0 ) should open the page in the current window and not initialize a new one.
If you're going to need a refresh on the same tab, you'll need selenium webdriver. After installing selenium using pip, you can use the following code
from selenium import webdriver
import time
import urllib
import urllib2
x=raw_input("Enter the URL")
refreshrate=raw_input("Enter the number of seconds")
refreshrate=int(refreshrate)
driver = webdriver.Firefox()
driver.get("http://"+x)
while True:
time.sleep(refreshrate)
driver.refresh()
This will open the url and refresh the tab every refreshrate
seconds
I use pyautogui module to refresh the browser page. It's one liner:
import pyautogui
pyautogui.hotkey('f5') #Simulates F5 key press = page refresh
Keep it very short, as simple as:
from selenium import webdriver
import time
driver = webdriver.Firefox()
driver.get('URL')
while True:
time.sleep(20)
driver.refresh()
driver.quit()