1

I am trying to download PDFs from this link. On clicking Read PDF, it opens a new window with PDF in it. On clicking the download button, it opens a dialog box and asks the user to specify the location to save the file.

After opening The webpage of the concerned e-book, I want to automate the following steps:

  1. Read PDF is clicked. The window is opened in new window.
  2. Download icon is clicked. Dialog box appears and asks to specify the file name and the location.
  3. The default name provided is kind of gibberish. So, the meaningful name like Frontmatter, Contents etc. is paseted there which is mentioned ahead of the download link and has been copied previously.

I want to automate above steps for a lot of ebooks. Had the links been in non-javascript form, it would have been easy to download using some kind of download manager.

(PS : The given webpage may not have all the Read PDF links activated but they are all active behind the proxy at my location.)

0

1 Answer 1

1
+50

I wrote the following JavaScript for you:

var ar = $('a.pdf-icon').each(function (a) 
{
  var ar = $(this).attr('onclick').split("'"); 
  var url = "http://ebooks.cambridge.org/open_pdf/" 
           + ar[3] 
           + "?pubCode=CUP&urlPrefix=cambridge&productCode=cbo";   
  alert("Press OK for next download");
  window.open(url);
});

To execute it, open the page you linked in your question, open JavaScript console (CTRL+SHIFT+I), and paste the above code into the console and press return. It will download all linked PDFs then.

Please note:

  • I tried this with Chrome and Firefox, both worked.
  • You might need to disable the popup blocker feature, otherwise it won't work
  • You might need to disable any PDF plugins you have in your browser, otherwise the PDFs might be displayed in the plugin instead of being downloaded
  • The script might need to be modified if the source code of the page is different when viewed through your proxy.
6
  • It is working fine. Could you please tell a way to add some delay between two consequent downloads? They all start downloading simultaneously and the browser gets overwhelmed. Also, is there a way by which add sensible names to the files, as mentioned in point 3. Sorry, I know very less of javascript so I have to ask such small questions. If not exact answer, any external link/tutorial will help too.
    – Gaurav
    Commented May 1, 2016 at 6:20
  • I added a line to the code which asks the user to press OK to proceed to the next download. I'm not aware of any ways to change the file names, I think it's only possible on the server side (so Cambridge would have to do this).
    – Bob
    Commented May 1, 2016 at 22:14
  • I appreciate your help, though I was looking for some kind of VB script automation to change the name of files.
    – Gaurav
    Commented May 2, 2016 at 6:50
  • Well changing the names using VB is easy, but you would have to provide a list of the file names from somewhere...
    – Bob
    Commented May 2, 2016 at 7:25
  • Each Read PDF is written is after the desired filename, like Frontmatter, Contents, etc. Is it possible to extract these filenames from source code or something and then proceed with file renaming?
    – Gaurav
    Commented May 4, 2016 at 4:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .