Refresh A Local Web Page Using Python
Solution 1:
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
Solution 2:
I use pyautogui module to refresh the browser page. It's one liner:
import pyautogui
pyautogui.hotkey('f5') #Simulates F5 key press = page refresh
Solution 3:
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()
Solution 4:
It looks like several people have asked this in the past but here is a link that sums it up.
But webbrowser.open( url, new=0 ) should open the page in the current window and not initialize a new one.
Solution 5:
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.)
Post a Comment for "Refresh A Local Web Page Using Python"