New to Python and having trouble figuring this out, any help is much appreciated.
I am using Selenium to grab ~150 PDFs and saving to a directory automatically, but the names are not descriptive.
The process is:
- iterate through a drop-down menu
- generate a PDF report that opens in a new tab
- save the report to a directory
Is there a way to name the files before saving by using the values in the drop-down?
Here is my setup:
# Set options:
chrome_options = Options()
download_dir = "C:\\Me\MyDirectory\Folder"
chrome_options.add_experimental_option('prefs', {
"download.default_directory": download_dir,
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"plugins.always_open_pdf_externally": True
}
)
b = webdriver.Chrome("C:\\Users\me\Downloads\chromedriver_win32\chromedriver.exe", options = chrome_options)
# Begin download
b.get('https://something.com')
inputs = Select(b.find_element_by_css_selector('#SpecialtyCode'))
input1 = len(inputs.options)
for items in range(input1):
inputs.select_by_index(items)
button = b.find_element_by_id('btnView')
button.click()