import os import json import shutil import sys import time from pathlib import Path from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys def create_directory(path): if not os.path.exists(path): os.makedirs(path) def get_user_downloads_path(): # Get the user's Downloads directory path in Windows general_downloads_path = Path.home() / "Downloads" return general_downloads_path def create_downloads_directory(): downloads_path = "D:/Python Projects/Title Search/Results/" create_directory(downloads_path) return downloads_path def create_folder_structure(downloads_path, appraiser_name, address_key): appraiser_path = os.path.join(downloads_path, appraiser_name) create_directory(appraiser_path) address_path = os.path.join(appraiser_path, address_key) create_directory(address_path) return address_path def create_folder_structure(downloads_path, tax_recorder_name, address_key): tax_recorder_path = os.path.join(downloads_path, tax_recorder_name) create_directory(tax_recorder_path) address_path = os.path.join(tax_recorder_path, address_key) create_directory(address_path) return address_path def run_appraiser(address_key): try: # Specify the downloads directory path downloads_path = create_downloads_directory() appraiser_name = "Appraiser" # Change this as needed # Specify the address and create a folder structure based on it #address_key = "2216 NW 6 PL FORT LAUDERDALE, FL 33311" # Change this as needed apprasier_path = create_folder_structure(downloads_path, appraiser_name, address_key) print_settings = { "recentDestinations": [{ "id": "Save as PDF", "origin": "local", "account": "", }], "selectedDestinationId": "Save as PDF", "version": 2, "isHeaderFooterEnabled": False, "isLandscapeEnabled": True } prefs = {'printing.print_preview_sticky_settings.appState': json.dumps(print_settings), "download.prompt_for_download": False, "profile.default_content_setting_values.automatic_downloads": 1, "download.directory_upgrade": True, "savefile.default_directory": apprasier_path, # this is path to dir where you want to save the file "safebrowsing.enabled": True} options = webdriver.ChromeOptions() options.add_experimental_option('prefs', prefs) options.add_argument('--kiosk-printing') service = Service() driver = webdriver.Chrome(options) driver.maximize_window() actions = ActionChains(driver) wait = WebDriverWait(driver, 20) driver.get("https://web.bcpa.net/BcpaClient/#/Record-Search") text_input = wait.until(EC.visibility_of_element_located((By.XPATH, '//input[@class="form-control"]'))).send_keys(address_key) search_button = driver.find_element(By.XPATH, '//span[@class="input-group-addon"]/span[@class="glyphicon glyphicon-search"]').click() printer_click = wait.until(EC.visibility_of_element_located((By.XPATH, '//div[@class="col-sm-1 btn-printrecinfo"]'))).click() time.sleep(10) except Exception as e: print(e) sys.exit(1) def run_tax_recorder(address_key): try: # Specify the downloads directory path downloads_path = create_downloads_directory() tax_recorder_name = "Tax_Recorder" # Change this as needed # Specify the address and create a folder structure based on it #address_key = "2216 NW 6 PL FORT LAUDERDALE, FL 33311" # Change this as needed tax_recorder_path = create_folder_structure(downloads_path, tax_recorder_name, address_key) print_settings = { "recentDestinations": [{ "id": "Save as PDF", "origin": "local", "account": "", }], "selectedDestinationId": "Save as PDF", "version": 2, "isHeaderFooterEnabled": False, "isLandscapeEnabled": True } prefs = {'printing.print_preview_sticky_settings.appState': json.dumps(print_settings), "download.prompt_for_download": False, "profile.default_content_setting_values.automatic_downloads": 1, "download.directory_upgrade": True, "savefile.default_directory": tax_recorder_path, # this is path to dir where you want to save the file "safebrowsing.enabled": True} options = webdriver.ChromeOptions() options.add_experimental_option('prefs', prefs) options.add_argument('--kiosk-printing') service = Service() driver = webdriver.Chrome(options) driver.maximize_window() actions = ActionChains(driver) wait = WebDriverWait(driver, 20) driver.get("https://broward.county-taxes.com/public/search/property_tax") pop_up_close = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@class="svg-icon"]'))).click() search_box = wait.until(EC.element_to_be_clickable((By.XPATH, '//input[@role="searchbox"]'))) search_box.send_keys("2216 NW 6 PL FORT LAUDERDALE") search_box.send_keys(Keys.RETURN) time.sleep(5) element_click = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@class="text-primary svg-icon"]'))).click() time.sleep(10) details_page = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[2]/div[2]/div/main/div/div/section[2]/div[2]/div[1]/div/div[2]/button'))).click() time.sleep(10) take_page_screenshot = driver.execute_script('window.print();') time.sleep(10) pdf_download = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="bill-history"]/div/div[2]/table/tbody[1]/tr[1]/td[5]/div/a/div/div[2]'))).click() time.sleep(10) # Get the latest downloaded PDF file general_downloads_path = get_user_downloads_path() downloaded_files = [fname for fname in os.listdir(general_downloads_path) if fname.endswith('.pdf')] if downloaded_files: latest_file = max(downloaded_files, key=lambda f: (general_downloads_path / f).stat().st_ctime) source_path = os.path.join(general_downloads_path, latest_file) # Move the file to the desired tax recorder path destination_path = os.path.join(tax_recorder_path, latest_file) shutil.move(source_path, destination_path) except Exception as e: print(e) sys.exit(1) if __name__ == "__main__": run_appraiser() run_tax_recorder()