0

So I'm trying to download pdf files from an ancient internal web system. I put in a request and based on my request parameters, it generates a new pdf and shows it in a new window. Since the pdfs are generated dynamically, there is no real url I could download.

I'm trying to figure out how I would download the file after it has generated and opened up in the new window.

The pertinent part of the page's source seems to be this:

    <body onload="document.FormForDownload.submit();">
    <form name="FormForDownload" method="get" action="./download.pdf" target="iframePDF">
        <iframe name="iframePDF"></iframe>
    </form>
</body>

I'm open to using the requests library or urllib or anything people suggest. ANy ideas? Working in python btw.

If I suppress chrome's own PDF viewer to get it to automatically download the pdf, I get a page that looks like this:

enter image description here

Clicking the open button will give me this page:

enter image description here

This is because the url generated is one time use only, to generate the url again, I have to request the pdf again.

doddy
  • 579
  • 5
  • 18
  • Try to disable the internal pdf viewer of browser, and it should directly download the pdf file. Check [here](https://stackoverflow.com/a/53588572/5319738) for an example. – Kamal Dec 05 '18 at 02:50
  • @Kamal I have tried that but it simply takes me to blank page with no download. And the main issue is that the pdf is simply returned at a generic link like domain.com/download.pdf? and this URL is only valid once. SO a request is sent to server, which generates a pdf and returns it at a one time generic url which opens in a new window. – doddy Dec 05 '18 at 03:26
  • Can you share the url? – Kamal Dec 05 '18 at 03:29
  • @Kamal cannot, requires authorization. – doddy Dec 05 '18 at 03:31
  • I do have another idea though, before it opens the new window with pdf, Chrome throws an alert. Until I accept or dismiss alert, the new window does not launch and I can go to that generic url and download pdf BUT selenium wont let me open a new tab while alert is present, throws UnexpectedAlertPresentException, any ideas on how to request new tab while alert is present? – doddy Dec 05 '18 at 03:32
  • I don't know how to do that.. Can you share screenshot of new window with and without pdf viewer enabled in chrome? – Kamal Dec 05 '18 at 03:35
  • Edited question to add screenshots. – doddy Dec 05 '18 at 03:44
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/184734/discussion-between-kamal-and-doddy). – Kamal Dec 05 '18 at 04:03
  • See if this helps - https://stackoverflow.com/a/60854430/5885718 – Bhuvanesh Mani Mar 25 '20 at 17:45

0 Answers0