Results 1 to 12 of 12

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

  1. #1
    Join Date
    Jul 2014

    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
    <tr id="listCFDIs_row6"  class="even"  onmouseover="this.className='highlight'"  onmouseout="this.className='even'" >
    <td style="text-align:center;" >650</td>
    <td style="text-align:center;" >CCI971201KP1</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>
    This part is what I suppose I should be interested in:
    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
    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
    Thank you, Kevin.
    Here's a screenshot of the user interface.

    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
    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
    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
    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:

    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
    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.

    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
    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
    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:

    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
    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:

    // ==UserScript==
    // @namespace   http://someuniquenamespace.com
    // @description Automated factura downloader. 
    // @version 	1
    // @include     https://www.portal.facturacfdi.mx/*
    // @grant       none
    // ==/UserScript==
    var but = document.createElement("input");
    but.value="show invoices";
    var bod=document.getElementsByTagName("body")[0];
    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+"',");
    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
    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

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.12213 seconds
  • Memory Usage 2,977KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (12)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (12)postbit
  • (12)postbit_onlinestatus
  • (12)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates