Last active
November 1, 2021 00:29
-
-
Save aaronkirkman/b61f4ce7c6e91bba718d0c7feaf042a5 to your computer and use it in GitHub Desktop.
Python code to download a file with Selenium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| from selenium import webdriver | |
| from selenium.webdriver.chrome.options import Options | |
| import time | |
| OUTPUT_DIR = "output" | |
| URL = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" | |
| # trailing slash is necessary | |
| prefs = {"download.default_directory": os.path.join(os.getcwd(), f"{OUTPUT_DIR}/"), | |
| "directory_upgrade": True, | |
| "safebrowsing_for_trusted_sources_enabled": False, | |
| "safebrowsing.enabled": False, | |
| "plugins.always_open_pdf_externally": True} | |
| options = Options() | |
| options.add_experimental_option("prefs", prefs) | |
| chromedriver_path = os.path.join(os.getcwd(), "chromedriver.exe") | |
| driver = webdriver.Chrome(executable_path=chromedriver_path, options=options) | |
| driver.get(URL) | |
| driver.implicitly_wait(60) | |
| time.sleep(30) | |
| driver.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment