www.webdeveloper.com
Results 1 to 12 of 12

Thread: Download contents of popups massively, probably html/browsing related

  1. #1
    Join Date
    Jul 2014
    Posts
    5

    Download contents of popups massively, probably html/browsing related

    Hi, what's up, everybody. This is Edgar and this is the first time I come here.

    So, straight to the point... There's a website I have to consult in order to have my invoices printed out. The problem is that I have over one thousand invoices to print, and I can only print them by clicking a button that opens a pop up window, which turns into a download dialog with the PDF file, one at a time... Which, of course, it's really time consuming and it may lead to errors.

    I was checking the source code and the list of invoices had this html format for each invoice
    Code:
    <tr id="listCFDIs_row6"  class="even"  onmouseover="this.className='highlight'"  onmouseout="this.className='even'" >
    <td>6</td>
    <td style="text-align:center;" >650</td>
    <td style="text-align:center;" >CCI971201KP1</td>
    <td>XXXX(2)</td>
    <td style="text-align:right;" >127525.74</td>
    <td style="text-align:center;" >22/07/2014 16:05:08</td>
    <td style="text-align:center;" ><img src='./imagenes/icons/activo16.png' style='border:0px'/></td>
    <td style="text-align:center;" >Sin Pagos</td>
    <td style="text-align:center;" ><a href=SCFDDetalle?sIdCFD=47398D67-331E-40AE-84E1-80E6C3107FED><img title='Ver detalle' border=0 src='./imagenes/icons/preliminar16.png' style='border:0px' title='Ver detalle'/></a><img title="Descargar PDF" src="imagenes/table/pdf.gif" class="img_cursor" onclick="window.open('SCFD2PDF?idcfd=47398D67-331E-40AE-84E1-80E6C3107FED','PDF', '' );"/><img title="Descargar XML" src="imagenes/icons/xml16.png" class="img_cursor" onclick="window.open('SXMLVer?idcfd=47398D67-331E-40AE-84E1-80E6C3107FED','XML', '' );"/><a href=SRegistrarPagoCFD?Id=47398D67-331E-40AE-84E1-80E6C3107FED><img src='./imagenes/icons/pago16.png' style='border:0px' title='Registrar pago'/></a></td>
    	</tr>
    This part is what I suppose I should be interested in:
    Code:
    onclick="window.open('SCFD2PDF?idcfd=47398D67-331E-40AE-84E1-80E6C3107FED','PDF', '' )
    I know nothing about javascript but my intuiton tells me I could automate the downloads somehow... So what can I do? is the string after the "window.open" a complement of a URL or how do I deal with this?

    I've tried a few extensions for chrome and firefox that are supposed to download all of the links, but none of the extensions listed the PDF files as a downloadable entity, they just list other things...


    I have no idea what I have to do, but I hope there's a way. Thank you all for your time and sorry for the long first post.

  2. #2
    Join Date
    Oct 2013
    Posts
    597
    A wild guess is that each invoice is getting created on-the-fly on the server. There's a bunch of data somewhere that's getting plugged into a template based on an "id", then the server creates the PDF (or whatever filetype is selected) and sends it to you. The actual invoices don't exist for download, mass or otherwise.

  3. #3
    Join Date
    Jul 2014
    Posts
    5
    Thank you, Kevin.
    Here's a screenshot of the user interface.
    http://www.tiikoni.com/tis/view/?id=e705209

    I understand what you mean, and if that's the case, then it's lamentable for me. However, is there an application or loop code or something for, say, firefox, that clicks the button and accepts the download as is and jumps to the next line and does the same? Something that already exists, because I don't know how to code yet.

    Thank you very much in advance.

  4. #4
    Join Date
    Oct 2013
    Posts
    597
    What I think it comes down to is this: If you don't have access to the server you're screwed. JavaScript is limited by the "Same Origin Policy". My guess is that whatever script is running on the server to output the files is also restricted similarly. For sure if it were mine it would be.

    I'd be asking the server administrator to find out if there's a way to dump all those invoices into a secure folder for you to access.

  5. #5
    Join Date
    Nov 2010
    Posts
    1,097
    if you just want it to work on your computer you could do this quite easily with a greasemonkey userscript. Basically, you would make a collection of the images you wanted to click, then loop through them, simulating a click on each one. If there really are over a thousand you might want to put in some sort of delay to avoid overloading the system (plus you will very quickly end up with 1000+ pop-up windows - do you really want this?)

    You may want to have it so that it clicks the icons say 20 at a time, then you can print those ones, then click a button and pop up the next 20 windows.

    Either way, that approach wouldn't automate the printing, it would just automate the "click-the-icon-and-pop-up-the-window" routine. Let us know if it sounds like what you're after and if you need more specifics

  6. #6
    Join Date
    Oct 2013
    Posts
    597
    Because I'm basically ignorant I looked up greasemonkey. Sounds neat, and if it works for the OP, well ... wow! Good suggestion! +1s to xelawho!

    Here's just one article:
    http://en.wikipedia.org/wiki/Greasemonkey

    I would highly second xelawho's comments on server load ('system') and the number of popup windows you'll get. Whatever script you write you will definitely need to keep both in mind. Assuming you choose to go this route.

  7. #7
    Join Date
    Jul 2014
    Posts
    5
    Quote Originally Posted by Kevin2 View Post
    I'd be asking the server administrator to find out if there's a way to dump all those invoices into a secure folder for you to access.
    I already asked someone from there and they said I had to do it one by one, but that person wasn't the server administrator, just an employee who wouldn't help any further.

    xelawho:
    The process that you describe suits what I'm after. I have like 1200 invoices from 2 companies and doing it manually would be quite painful. The user interface lets me visualize either 15, 30, 50 or 100 results, so I'll go with 15, if the only way is to open the file right after clicking on the button. However, I think it would be best if the script chooses to save the pdf instead of opening it, it's a simple download dialog after all and it lets me choose to either open or save the file, so if I save them all in the same directory, I can simply right click on it and choose "print" and it will do everything automatically, and I will have the invoice ready for any other printing day... now, is that possible?

    Thanks in advance

  8. #8
    Join Date
    Nov 2010
    Posts
    1,097
    hmmm, hard to say from this end and i guess it would need some testing. But the first question would be is the print/save dialog created by the page, or it your standard windows/mac/whatever you are using print dialog?

    I have a feeling that the best you're going to be able to do is open those 15, click on "save file", open another 15, repeat - then at least you will end up with them all in the same folder. But like I say it's hard to say specifically what can and can't be done without seeing it in action.

  9. #9
    Join Date
    Jul 2014
    Posts
    5
    As soon as I click the gif icon for PDF, the screen doesn't freeze or anything, it just shows this regular dialog in firefox + windows 7:
    http://www.tiikoni.com/tis/upload/up...php?id=217cb13

    And I can click the other pdf gifs freely... Everything in the same folder is no problem.

    Sorry for the delay.

  10. #10
    Join Date
    Nov 2010
    Posts
    1,097
    hmm. Looks like a windows dialog, which greasemonkey can't interact with. But we can get close, automating the click on the icons and bringing up that dialog. I'm not sure how that dialog works in terms of remembering preferences, but if you install the userscript, then select "guardar archivo" and then "repetir esta decisión..." you may find that the files get automatically saved to the folder you specify.

    To install the userscript: open up firefox without opening the factura page and download greasemonkey from here: https://addons.mozilla.org/en-US/fir.../greasemonkey/

    greasemonkey is the program that allows you to run userscripts.

    then, save this code, as is, in a file called "invoice_downloader.user.js" - the extensions are important:

    Code:
    // ==UserScript==
    // @namespace   http://someuniquenamespace.com
    // @description Automated factura downloader. 
    // @version 	1
    // @include     https://www.portal.facturacfdi.mx/*
    // @grant       none
    // ==/UserScript==
    
    (function(){		
    var but = document.createElement("input");
    but.type="button";
    but.value="show invoices";
    but.onclick=clicker;
    var bod=document.getElementsByTagName("body")[0];
    bod.insertBefore(but,bod.firstChild);	
    
    function clicker(){
    var imgs= document.querySelectorAll("img[title='Descargar PDF']");
    for (i=0; i<imgs.length; i++){
    var str=imgs[i].getAttribute('onclick').replace(",'PDF',",",'PDF"+i+"',");
    imgs[i].setAttribute("onclick",str);
    imgs[i].click();
    	}
    }
    })();
    firefox should now have a little monkey head at the top right. Click on the down arrow next to it, go to "manage user scripts", click the cog thingy top right, install add-on from file and choose the file you just created.

    Now when you load the factura page there should be a button at the top of the screen that says "show invoices" - click that and hopefully something will happen

  11. #11
    Join Date
    Jul 2014
    Posts
    5
    Quote Originally Posted by xelawho View Post
    Now when you load the factura page there should be a button at the top of the screen that says "show invoices" - click that and hopefully something will happen
    Holy $%#%, That was EXCELLENT, sir. I had to drag the script into the browser instead of using the manager, but it worked excellently and automatically. I've gotta learn to do that.

    Thank you very much, you just saved me a thousand hours.

  12. #12
    Join Date
    Nov 2010
    Posts
    1,097
    Orale!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles