- указать имя файла перед его сохранением
- контролировать, где находится файл
ser_name = os.environ.get('username')
options = webdriver.ChromeOptions()
download_path = f"C:\\Users\\{user_name}\\Documents\\mr\\"
# Define settings with the download path
settings = {
"recentDestinations": [{
"id": "Save as PDF",
"origin": "local",
"account": "",
}],
"selectedDestinationId": "Save as PDF",
"version": 2,
"saveToLocalPath": download_path
}
# Define preferences
prefs = {
'printing.print_preview_sticky_settings.appState': json.dumps(settings),
"download.default_directory": download_path, # Change default directory for downloads
"download.prompt_for_download": False, # To auto download the file
"download.directory_upgrade": True,
"plugins.always_open_pdf_externally": True # It will not show PDF directly in chrome
}
# Set up Chrome options
options.add_experimental_option('prefs', prefs)
options.add_argument('--kiosk-printing')```
driver.execute_script('window.print();')
Подробнее здесь: https://stackoverflow.com/questions/786 ... ument-goes