title: R: How to download PDF using rvest while in authentificated session
body: <p>I am trying to scrape PDFs from a newspaper archive that uses password protection, using rvest. The problem is that while I can log in in a session, I couldn't find a way to use the download.file() command within the session. The website is somewhat strange, so the only option I've found so far to actually log in was by actually using the PDF link.</p>
  <p>Here is my current code (unfortunately, as I can't give out the login details, it is only limitedly reproducible):</p>
  <pre><code>#login to DLG archive
  login &lt;- &quot;https://dlgarchiv.lv.de/pdf/616694ca9b67fDLG_14-19_10_2021.pdf&quot;
  pgsession &lt;- session(login)
  pgform &lt;- html_form(pgsession)[[1]]
  filled_form &lt;- html_form_set(pgform, customerno=&quot;*******&quot;, plz=&quot;*****&quot;)
  session_submit(filled_form)
  
  #download file
  download.file(url=&quot;https://dlgarchiv.lv.de/pdf/616694ca9b67fDLG_14-19_10_2021.pdf&quot;,destfile=&quot;test.pdf&quot;,mode=&quot;wb&quot;)
  </code></pre>
  <p>As a result, I am only downloading an HTML document of the log-in page, i.e. my log-in is being &quot;forgotten&quot; in between.</p>
  <p>Looking at the output following the session_submit() command, I am actually getting to the PDF, but I can't download it...</p>
  <pre><code>&lt;session&gt; https://dlgarchiv.lv.de/pdf/616694ca9b67fDLG_14-19_10_2021.pdf
    Status: 200
    Type:   application/pdf
    Size:   1394950
  </code></pre>