1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Need help with Javascript/ HTML page for data download

Discussion in 'Programming & Webmastering' started by douglatins, Aug 8, 2011.

  1. douglatins

    douglatins

    Joined:
    May 15, 2008
    Messages:
    2,863 (1.26/day)
    Thanks Received:
    273
    Location:
    Brasil
    I have a page that i select some information regarding product import export.
    I select from dropdown menus the port which the goods go out, and select in another dropdown menus my detailing, which i select product number and city in another.

    So i get import data from a choosen port of each product and from which city they came from.

    Then i press query, but its a javascript button, so i lose all the information i sent in the previous page, then i choose to download it, and tick a box for excel file and press send.
    But i want to in some way automate that proccess, that by just creating a link i get to download the file, so i can run a script that follows hundred of links and download me the files.

    How can i do that?

    [​IMG]

    Attached Files:

    • Code.txt
      File size:
      119.9 KB
      Views:
      105
    Last edited: Aug 8, 2011
  2. streetfighter 2

    streetfighter 2 New Member

    Joined:
    Jul 26, 2010
    Messages:
    1,658 (1.13/day)
    Thanks Received:
    732
    Location:
    Philly
    Ajax?
  3. douglatins

    douglatins

    Joined:
    May 15, 2008
    Messages:
    2,863 (1.26/day)
    Thanks Received:
    273
    Location:
    Brasil
    I have a image and a code example of the page

    About Ajax i have no idea
  4. streetfighter 2

    streetfighter 2 New Member

    Joined:
    Jul 26, 2010
    Messages:
    1,658 (1.13/day)
    Thanks Received:
    732
    Location:
    Philly
    Oh, my bad. I thought you were writing the code for the page. I see you just want to automate/wrap the interface.

    Let me put my thinking cap on . . . :D ;)

    EDIT: After looking at the code, at least the part that you provided, I have to say it may be kinda tough. The form is awfully dynamic (not to mention the code is mostly in Spanish/Portuguese) and it uses AJAX and JSON as far as I can tell. I'm guessing you'll need to do fill out the proper JSON structure with the data you have then use the page's javascript methods to get a URL to the excel download. Unfortunately I can't investigate it further without having access to the page in question.

    EDIT2: I think IlluminAce is correct. The page does use AJAX but the form is still using POST. For whatever reason my browser wasn't opening the entire code you posted :laugh:.
    Last edited: Aug 8, 2011
    douglatins says thanks.
  5. IlluminAce

    IlluminAce New Member

    Joined:
    Aug 6, 2011
    Messages:
    46 (0.04/day)
    Thanks Received:
    40
    Location:
    UK
    Before I go further, I'd just say if you're intending to make many repeated automated requests to this website, bear in mind that not all webmasters will approve of this - you may be contravening guidelines somewhere. Check first.

    That said...


    Follow through the javascript to understand what it's doing.

    Code:
    <button id="btnPesquisar" class="botao ui-corner-all" type="button">Query</button>
    Now search for btnPresquisar

    Code:
    $('#btnPesquisar').click(function(){
    ... lots of validation JS...

    Code:
    			if(!formValidate()){
    
    				return false;
    
    			} else {
    
    				$('#frmConsulta').submit();
    
    			}
    ... so what it finally gets round to doing is submitting the form frmConsulta. Which is:

    Code:
    <form name="frmConsulta" id="frmConsulta"
    
    	action="http://aliceweb2.mdic.gov.br//consulta-ncm/consultar" method="post"
    So it simply navigates to the page http://aliceweb2.mdic.gov.br//consulta-ncm/consultar, passing the values you've entered as part of a POST request. To do this programatically, you'd construct a HTTP POST request - get an idea how here, including your values as required (get the correct key names from the code).

    Retrieve the page returned, and you'll have to do something similar again to acquire the xls file.
    douglatins and qubit say thanks.
  6. douglatins

    douglatins

    Joined:
    May 15, 2008
    Messages:
    2,863 (1.26/day)
    Thanks Received:
    273
    Location:
    Brasil
    It still is very difficult i have no idea what i'm doing
  7. IlluminAce

    IlluminAce New Member

    Joined:
    Aug 6, 2011
    Messages:
    46 (0.04/day)
    Thanks Received:
    40
    Location:
    UK
    Hmm, I'd suggest that this may be more work than you're hoping to perform then. You need to understand HTML and JS (which aren't difficult languages to muster, but you still need some understanding), plus another language to code your program (such as Java, Python, etc). I would write a little for you to help get you started, but I honestly don't have the time.

    Failing the programmatic approach, you could automate the process with macro-style applications which record mouse movements and keystrokes. It's highly inelegant, not at all robust, would be very slow to execute, likely to fall over all the time, and probably a real pain to get going in the first place (there's a sales pitch for you!) - you may even need to write code for it, to type in your different inputs - but it might be sort-of simple to throw together. Googling "mouse macro freeware" throws up some results, but I wouldn't really advise this approach.
    qubit says thanks.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page