如何控制a";另存为;使用Python在网页上打开的窗口?

如何控制a";另存为;使用Python在网页上打开的窗口?,python,selenium,selenium-webdriver,automation,webdriver,Python,Selenium,Selenium Webdriver,Automation,Webdriver,因此,我使用Selenium和Python来浏览网站,并单击打开“另存为”窗口的按钮。我怎样才能控制那个窗口?我需要先发送一个路径,文件应该保存在哪里,还要修改文件名,然后单击“保存” 我想我不能使用Selenium来实现这一点,因为打开它的“另存为”窗口是一个系统对话框窗口 我应该使用什么工具或Python脚本来完成我需要做的事情? 如何使用Python控制系统对话框窗口?您可以使用类似pyautogui的GUI自动化包。代码注释中的解释 import pyautogui import tim

因此,我使用Selenium和Python来浏览网站,并单击打开“另存为”窗口的按钮。我怎样才能控制那个窗口?我需要先发送一个路径,文件应该保存在哪里,还要修改文件名,然后单击“保存”

我想我不能使用Selenium来实现这一点,因为打开它的“另存为”窗口是一个系统对话框窗口

我应该使用什么工具或Python脚本来完成我需要做的事情?
如何使用Python控制系统对话框窗口?

您可以使用类似pyautogui的GUI自动化包。代码注释中的解释

import pyautogui
import time

# To simulate a Save As dialog. You can remove this since you'll be saving/downloading a file from a link
pyautogui.hotkey('ctrl', 's')
# Wait for the Save As dialog to load. Might need to increase the wait time on slower machines
time.sleep(1)
# File path + name
FILE_NAME = 'C:\\path\\to\\file\\file.ext'
# Type the file path and name is Save AS dialog
pyautogui.typewrite(FILE_NAME)
#Hit Enter to save
pyautogui.hotkey('enter')

非常感谢,效果非常好!!!!!!!另外,你能告诉我是否有办法将“file.ext”变成一个我可以更改的参数吗?语法如何?可以将变量FILE_NAME='C:\\path\\to\\FILE\\FILE.ext'更改为任何有效的路径和文件名。是否可以更改另存为类型:网页,单个文件(*.mhtml)?