首页 > 解决方案 > Webdriver:在保存到文件夹之前更改文件名

问题描述

当我使用webdriver浏览网站时,它会自动将文件下载到我的文件夹中,但是文件名为“Bike.gz”,是否可以将其名称更改为“{当前时间}.txt”,然后再保存到我的文件夹?例如,如“2019-03-07-11-46.txt”。

代码:

options = webdriver.ChromeOptions()
options.add_experimental_option("prefs", {  
"download.default_directory": r"\\xxx.xx.xxx.xx\bike_test",  
"download.prompt_for_download": False,  
"download.directory_upgrade": True,   
"safebrowsing.enabled": True
}) 
driver_main = webdriver.Chrome(chrome_options=options) 
driver_main.get("http://data.xxxx/xxxx")

另外,“\xxx.xx.xxx.xx\bike_test”是我的 NAS 路径,如果我在 AWS 上运行它,如何下载文件并将其直接保存到我的 NAS 文件夹bike_test?还是我必须先将其保存在我的 AWS 文件夹中,然后再对其进行转换?

标签: pythonwebdrivernas

解决方案


推荐阅读