Reputation: 1
I have a web database, which every day at work I have to go and download manually, then save it in a folder on the company's network.
There are 4 files and my question is simple: how can I automate this task? It seems simple but doing this every day is a real pain... In my company, we have restrictions on using some python libraries, such as pyautogui etc...
So I would need a simple suggestion, which I'll try to learn how to do. Thanks :)
Pyautogui, python libraries
Upvotes: 0
Views: 151
Reputation: 20342
Something like this should do it. Of course, you need to customize the code for your specific use case.
# download from web
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
options = webdriver.ChromeOptions()
driver = webdriver.Chrome('C:/Utility/chromedriver.exe')
driver.get('https://cdr.ffiec.gov/public/PWS/DownloadBulkData.aspx')
listproduct = ['Call Reports -- Single Period',
'Call Reports -- Balance Sheet, Income Statement, Past Due -- Four Periods']
options = webdriver.ChromeOptions()
options.add_experimental_option("prefs", {"download.default_directory": r"C:\\Users\\ryans\\OneDrive\\Desktop\\my_desktop\\", "download.prompt_for_download": False, "download.directory_upgrade": True, "safebrowsing.enabled": True})
for product in listproduct:
try:
Weblistbox=WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID,"ListBox1")))
select=Select(Weblistbox)
select.select_by_visible_text(product)
print("Product {} is selected".format(product))
for year in range(0,4):
datedropdown = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "DatesDropDownList")))
select = Select(datedropdown)
select.select_by_index(year)
datedropdown = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "DatesDropDownList")))
select = Select(datedropdown)
print("DateOrYear {} is selected".format(select.first_selected_option.text))
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID,'Download_0'))).click()
except:
print('out of range...')
Upvotes: 0