Skip to content

Instantly share code, notes, and snippets.

@sposterkil
Created June 10, 2016 23:30
Show Gist options
  • Save sposterkil/8fcbd9d87d848b9666d7dacaa5573f4d to your computer and use it in GitHub Desktop.
Save sposterkil/8fcbd9d87d848b9666d7dacaa5573f4d to your computer and use it in GitHub Desktop.
A little python script to refresh a given URL every 10 seconds
#! /usr/bin/env python3
import webbrowser
from time import sleep
url = input('Input the URL to reload, including "http://: ')
while True:
print("refreshing...")
webbrowser.open(url, new=0)
sleep(10)
@sposterkil
Copy link
Author

Heads up, this script may open a new tab on every refresh... It's not supposed to, but it is on my machine

@prasadadhav
Copy link

Yes, this does open up new tabs.
But thanks for the code.

@deletedaccount00
Copy link

What does new=0 do ? In line 10

@sposterkil
Copy link
Author

sposterkil commented Dec 22, 2020

What does new=0 do ? In line 10

According to the documentation, it means “reuse an existing window”, but that has never seemed to work reliably.

@prasadadhav
Copy link

I think it is to not open a new tab each time we refresh.
But please correct me if I am wrong.

@vinayanand3
Copy link

But even if we use new=0, this opens up new tabs everytime

@DevSachinOps
Copy link

This script is basically written to open a url which is given above in the script.
So new=0 opens the url in new tab.
new=1 opens the url in new window.

@sposterkil
Copy link
Author

This code is five years old and has never really worked properly - if you’re looking for this functionality, my suggestion (provided with no warranty or assumption of liability) is https://gitlab.com/alanramsey/auto-reload-tab

@PaoloChreif
Copy link

PaoloChreif commented Apr 26, 2022

I found that just using the auto GUI (pyautogui) and using it to automatically press f5 is better. First pip install pyautogui then use the following:

import pyautogui
import time

for i in range(number of times you want to refresh):
    time.sleep(refreshrate in seconds)
    pyautogui.hotkey('f5')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment