Skip to content

Instantly share code, notes, and snippets.

@KnightChaser
Created March 25, 2025 06:07
Show Gist options
  • Save KnightChaser/37783e0c472136a24781c88e9e5cd4ed to your computer and use it in GitHub Desktop.
Save KnightChaser/37783e0c472136a24781c88e9e5cd4ed to your computer and use it in GitHub Desktop.
A Python3 code utilizing chrome driver to automatically send refresh(F5) to the target website as much as specified.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from tqdm import tqdm
import time
# Configuration
num = 1234 # How many times?
url = "www.example.com" # To where?
# Set up Chrome options (use headless mode if you don't need a visible browser)
chrome_options = Options()
chrome_options.add_argument("--headless") # Optional: remove if you need a visible browser
chrome_options.add_argument("--disable-gpu")
# Initialize the Chrome driver using webdriver-manager
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
# Loop with tqdm to track progress
for i in tqdm(range(num), desc="Accessing pages"):
try:
driver.get(url)
# Optional: wait for a few seconds to let the page load fully (adjust as needed)
time.sleep(0.75)
# print(f"Request {i+1}: Page title - {driver.title}")
except Exception as e:
print(f"Request {i+1}: Failed - {e}")
# Cleanup: close the browser when done
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment