• 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

Joined
May 15, 2008
Messages
2,863 (0.49/day)
Location
Brasil
System Name Sovereign // HTPC
Processor i7 3770k 4.2 // i7 3770k 4.2
Motherboard Maximus V Gene // Sabertooth Z77
Cooling Noctua D14 // Intel HSF
Memory 16GB Samsung // 16GB VengeanceLP
Video Card(s) Deciding // 660 DC2
Storage OS (X25-M), Data (Seagate 1TB) // Samsung 840 120GB & bunch of drives
Display(s) Samsung T240HD // LG TV
Case TJ08e // Grandia GD08
Audio Device(s) DT880 Pro 250 ohm // TV speakers
Power Supply Seasonic Plat 1000 // Seasonic Gold 760
Software Windows 8 Pro x64 // Windows 7 Pro x64
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?

 

Attachments

  • Code.txt
    119.9 KB · Views: 309
Last edited:
Joined
May 15, 2008
Messages
2,863 (0.49/day)
Location
Brasil
System Name Sovereign // HTPC
Processor i7 3770k 4.2 // i7 3770k 4.2
Motherboard Maximus V Gene // Sabertooth Z77
Cooling Noctua D14 // Intel HSF
Memory 16GB Samsung // 16GB VengeanceLP
Video Card(s) Deciding // 660 DC2
Storage OS (X25-M), Data (Seagate 1TB) // Samsung 840 120GB & bunch of drives
Display(s) Samsung T240HD // LG TV
Case TJ08e // Grandia GD08
Audio Device(s) DT880 Pro 250 ohm // TV speakers
Power Supply Seasonic Plat 1000 // Seasonic Gold 760
Software Windows 8 Pro x64 // Windows 7 Pro x64
I have a image and a code example of the page

About Ajax i have no idea
 

streetfighter 2

New Member
Joined
Jul 26, 2010
Messages
1,655 (0.33/day)
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:

IlluminAce

New Member
Joined
Aug 6, 2011
Messages
46 (0.01/day)
Location
UK
System Name Ace2
Processor Intel i7 2600
Motherboard ASRock Extreme4 Gen3
Cooling Zalman CNPS10x Extreme
Memory Corsair Vengeance LP 16GB (4x4)
Video Card(s) Asus HD 6970 DirectCUII
Storage 4x Samsung 1TB 7.2krpm
Display(s) 1x 24" 16:10, 1x 20" 16:10, 3x 19" 5:4
Case Fractal Design R3
Audio Device(s) TBD
Power Supply Corsair HX850W
Software Debian dom0 (on Xen hypervisor)
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.
 
Joined
May 15, 2008
Messages
2,863 (0.49/day)
Location
Brasil
System Name Sovereign // HTPC
Processor i7 3770k 4.2 // i7 3770k 4.2
Motherboard Maximus V Gene // Sabertooth Z77
Cooling Noctua D14 // Intel HSF
Memory 16GB Samsung // 16GB VengeanceLP
Video Card(s) Deciding // 660 DC2
Storage OS (X25-M), Data (Seagate 1TB) // Samsung 840 120GB & bunch of drives
Display(s) Samsung T240HD // LG TV
Case TJ08e // Grandia GD08
Audio Device(s) DT880 Pro 250 ohm // TV speakers
Power Supply Seasonic Plat 1000 // Seasonic Gold 760
Software Windows 8 Pro x64 // Windows 7 Pro x64
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.

It still is very difficult i have no idea what i'm doing
 

IlluminAce

New Member
Joined
Aug 6, 2011
Messages
46 (0.01/day)
Location
UK
System Name Ace2
Processor Intel i7 2600
Motherboard ASRock Extreme4 Gen3
Cooling Zalman CNPS10x Extreme
Memory Corsair Vengeance LP 16GB (4x4)
Video Card(s) Asus HD 6970 DirectCUII
Storage 4x Samsung 1TB 7.2krpm
Display(s) 1x 24" 16:10, 1x 20" 16:10, 3x 19" 5:4
Case Fractal Design R3
Audio Device(s) TBD
Power Supply Corsair HX850W
Software Debian dom0 (on Xen hypervisor)
It still is very difficult i have no idea what i'm doing

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