Это код для открытия хрома с использованием селена и загрузки файла, нажав на кнопку.
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# Options for Chrome WebDriver
op = Options()
op.add_argument('--disable-notifications')
op.add_experimental_option("prefs",{
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"safebrowsing.enabled": True
})
# Download Path
download_dir = 'D:\\'
# Initializing the Chrome webdriver with the options
driver = webdriver.Chrome(options=op)
# Setting Chrome to trust downloads
driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': download_dir}}
command_result = driver.execute("send_command", params)
driver.implicitly_wait(5)
# Opening the page
driver.get("https://apa.nexregreporting.com/home/portfoliocompression")
# Click on the button and wait for 10 seconds
driver.find_element_by_xpath('//*[@class="btn btn-default"]').click()
time.sleep(10)
# Closing the webdriver
driver.close()