Skip to content

Instantly share code, notes, and snippets.

@POPULARWEB6231
Created October 8, 2022 13:58
Show Gist options
  • Save POPULARWEB6231/9da87879de572b13e715a6c901355400 to your computer and use it in GitHub Desktop.
Save POPULARWEB6231/9da87879de572b13e715a6c901355400 to your computer and use it in GitHub Desktop.
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
chromeOptions = webdriver.ChromeOptions()
prefs = {"download.default_directory": r"C:\Users\popularweb6231\python_work\fltp_files\downloads\\"}
chromeOptions.add_experimental_option("prefs", prefs)
chromedriver = "C:/Users/popularweb6231/chromedriver.exe"
driver = webdriver.Chrome(executable_path=chromedriver, options=chromeOptions)
url = "https://dos.elections.myflorida.com/committees/downloadcomlist.asp"
# create a new Chrome session
driver.implicitly_wait(30)
driver.get(url)
# Find download button and click it.
click_field = driver.find_element(By.NAME, 'CanDownload')
click_field.click()
# This is supposed to make it wait, but it didn't?
driver.implicitly_wait(10)
# So I had to make it wait here, like this to give it time to download.
time.sleep(5)
# Rename file according to date.
from rename_file import rename_file
rename_file()
import os
from datetime import date
def rename_file():
# Find today's date to name the file.
today = date.today().strftime("%m_%d_%Y_")
# Find the file and set new naming convention.
old_name = r'C:/Users/popularweb6231/python_work/fltp_files/downloads/DoeCommitteeList.txt'
new_name = f"C:/Users/popularweb6231/python_work/fltp_files/downloads/{today}DoeCommitteeList.txt"
# Make sure not to overwrite if we already changed it.
if os.path.isfile(new_name):
print("The file already exists.")
# Rename that sucker.
else:
os.rename(old_name, new_name)
rename_file()
@iglama
Copy link

iglama commented Dec 19, 2023

Uploading IMG_4826.png…

@iglama
Copy link

iglama commented Dec 19, 2023

Code.py

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