Selenium デフォルトダウンロードディレクトリを変更する(Chrome, Python)
- Selenium 4.9.0
- Chrome 112
- ChromeDriver 112.0.5615.49
- Python 3.11
from selenium.webdriver import (
Chrome,
ChromeOptions,
)
download_dir = "./downloads"
os.makedirs(download_dir, exist_ok=True)
options = ChromeOptions()
options.add_experimental_option("prefs", {
"profile.default_content_settings.popups": 0,
"download.default_directory": os.path.realpath(download_dir),
"download.prompt_for_download": False,
"download.directory_upgrade": True,
})
driver = Chrome(
options=options,
)