Selenium Webdriver: How to Download a PDF File with Python? Selenium Webdriver: How to Download a PDF File with Python? selenium selenium

Selenium Webdriver: How to Download a PDF File with Python?


Try this code, it worked for me.

options = webdriver.ChromeOptions()options.add_experimental_option('prefs', {"download.default_directory": "C:/Users/XXXX/Desktop", #Change default directory for downloads"download.prompt_for_download": False, #To auto download the file"download.directory_upgrade": True,"plugins.always_open_pdf_externally": True #It will not show PDF directly in chrome})self.driver = webdriver.Chrome(options=options


You can download the pdf (Embeded pdf & Normal pdf) from web using selenium.

from selenium import webdriverdownload_dir = "C:\\Users\\omprakashpk\\Documents" # for linux/*nix, download_dir="/usr/Public"options = webdriver.ChromeOptions()profile = {"plugins.plugins_list": [{"enabled": False, "name": "Chrome PDF Viewer"}], # Disable Chrome's PDF Viewer               "download.default_directory": download_dir , "download.extensions_to_open": "applications/pdf"}options.add_experimental_option("prefs", profile)driver = webdriver.Chrome('C:\\chromedriver\\chromedriver_2_32.exe', chrome_options=options)  # Optional argument, if not specified will search path.driver.get(`pdf_url`)

It will download and save the pdf in directory specified. Change the download_dir location and chrome driver location as per your convenience.

You can download chrome driver from here.

Hope it helps!


I did it and it worked, don't ask me how :)

options = webdriver.ChromeOptions()options.add_experimental_option('prefs', {#"download.default_directory": "C:/Users/517/Download", #Change default directory for downloads#"download.prompt_for_download": False, #To auto download the file#"download.directory_upgrade": True,"plugins.always_open_pdf_externally": True #It will not show PDF directly in chrome })driver = webdriver.Chrome(options=options)