使用 Selenium webdriver 上传最近下载的文件- PYTHON
Upload recent downloaded file using Selenium webdriver- PYTHON
我想使用 Selenium 上传一个我不知道名字的文件,我唯一知道的是它在下载文件夹中,而且是最近的文件。我该怎么做?
与硒无关。您可以使用 python 中的本机库来获得所需的结果。
import os
import glob
# * matches all files in directory
# if you need other specific file types
# use *.[type], for example *.py
files_in_dir = glob.glob('[path to your folder]/*')
recent_file = max(list_of_files, key=os.path.getctime)
os.path.getctime
指的是系统中当前路径的最后一次元数据更改时间。这样您就可以过滤掉并获取最近日期的最新文件。
glob
模块用于在指定目录中查找特定文件模式。阅读更多关于 glob
here.
os
模块提供了一些来自操作系统的实用功能。更多关于 os
here.
我想使用 Selenium 上传一个我不知道名字的文件,我唯一知道的是它在下载文件夹中,而且是最近的文件。我该怎么做?
与硒无关。您可以使用 python 中的本机库来获得所需的结果。
import os
import glob
# * matches all files in directory
# if you need other specific file types
# use *.[type], for example *.py
files_in_dir = glob.glob('[path to your folder]/*')
recent_file = max(list_of_files, key=os.path.getctime)
os.path.getctime
指的是系统中当前路径的最后一次元数据更改时间。这样您就可以过滤掉并获取最近日期的最新文件。
glob
模块用于在指定目录中查找特定文件模式。阅读更多关于 glob
here.
os
模块提供了一些来自操作系统的实用功能。更多关于 os
here.