title: How can I download a PDF file from an URL where the PDF is embedded into the HTML?
body: <p><strong>What I'm trying to do:</strong> I want to scrape a web page to get the amount of a financial transaction from a PDF file that is loaded with javascript from a website. Example website: <a href="http://www.nebraskadeedsonline.us/document.aspx?g5savSPtTDnumMn1bRBWoKqN6Gu65tBhDE9%2fVs5YdPg=" rel="nofollow noreferrer">http://www.nebraskadeedsonline.us/document.aspx?g5savSPtTDnumMn1bRBWoKqN6Gu65tBhDE9%2fVs5YdPg=</a></p>
  
  <p>When I click the 'View Document' button, the PDF file loads into my browser's window (I'm using Google Chrome). I can right-click on the PDF and save it to my computer, but I want to automate that process by either having Selenium (or similar package) download that file and then process it for OCR.</p>
  
  <p>If I can get it saved, I will be able to do the OCR part (I hope). I just can't get the file saved.</p>
  
  <p>From <a href="https://stackoverflow.com/questions/43470535/python-download-pdf-embedded-in-a-page/43471196#43471196">here</a>, I found and modified this code:</p>
  
  <pre><code>def download_pdf(lnk):
  
      from selenium import webdriver
      from time import sleep
  
      options = webdriver.ChromeOptions()
  
      download_folder = "C:\\Users\\rickc\\Documents\\Scraper2\\screenshots\\"
  
      profile = {"plugins.plugins_list": [{"enabled": False,
                                           "name": "Chrome PDF Viewer"}],
                 "download.default_directory": download_folder,
                 "download.extensions_to_open": ""}
  
      options.add_experimental_option("prefs", profile)
  
      print("Downloading file from link: {}".format(lnk))
  
      driver = webdriver.Chrome(chrome_options = options)
      driver.get(lnk)
  
      filename = lnk.split("/")[3].split(".aspx")[0]+".pdf"
      print("File: {}".format(filename))
  
      print("Status: Download Complete.")
      print("Folder: {}".format(download_folder))
  
      driver.close()
  
  download_pdf('http://www.nebraskadeedsonline.us/document.aspx?g5savSPtTDnumMn1bRBWoKqN6Gu65tBhDE9fVs5YdPg=')
  </code></pre>
  
  <p>But it isn't working. My old college professor once said, "If you've spent more than two hours on the problem and haven't made headway, it's time to look for help elsewhere." So I'm looking for help.</p>
  
  <p><strong>Other info:</strong> The link above will take you to a web page, but you can't access the PDF document until you click on the 'View Document' button. I've tried using Selenium's <code>webdriver.find_element_by_ID('btnDocument').click()</code> to make things happen, and it just loads the page but doesn't do anything with it.</p>