import os
from selenium import webdriver
from datetime import datetime
# Set the path for the parent folder
path = "E:\\selenium_test\\date\\"
# Get the current date
now = datetime.now()
# Create the folder name using the current date
folder_name = f"{now.year}-{now.month}-{now.day}"
# Create the full path for the folder
full_path = os.path.join(path, folder_name)
# Create the folder
os.mkdir(full_path)
# Set the download directory for Selenium
options = webdriver.ChromeOptions()
prefs = {'download.default_directory': full_path}
options.add_experimental_option('prefs', prefs)
# Create the Selenium webdriver with the options
driver = webdriver.Chrome(options=options)
1条答案
按热度按时间68de4m5k1#
这应该行得通:
运行代码时,它将根据当前日期创建一个新文件夹,并将该文件夹用作selenium的下载目录。