-
-
Save POPULARWEB6231/9da87879de572b13e715a6c901355400 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment