jscript issues with downloading a zip from the Web

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 539
Joined: 07 Jan 2016 07:47

jscript issues with downloading a zip from the Web

#1 Post by SIMMS7400 » 04 Jun 2020 04:41

HI Folks -

I have the following jscript (that you guys helped me with last year) to download a zip file from the Web. The script stopped working recently and I believe it's due to the format of the Webpage.

Code: Select all

@if (@a)==(@b) @end /* Batch part:
@ECHO off &SETlocal

::-- Download Link --::
CSCRIPT //nologo //e:jscript "%~fs0" "ME_PS_PATH=C:\ManageEngine\ServiceDesk\Patch_Sets"

pause
JScript Part : */

var objIE = null;
try {
  WScript.ECHO('Searching link ...');
  objIE = new ActiveXObject('InternetExplorer.Application');
  // objIE.Visible = true;
  objIE.Navigate('https://www.manageengine.com/products/service-desk/service-packs.html');
  while (objIE.Busy) { WScript.Sleep(100); }
  var link = objIE.document.getElementsByClassName('box-table mT20')[0].getElementsByTagName('tr')[2].getElementsByTagName('td')[2].getElementsByTagName('a')[0].getAttribute('href');
  objIE.Quit();
  objIE = null;
  WScript.ECHO('Found: ' + link);

  WScript.ECHO('Downloading ...');
  var objXMLHTTP = new ActiveXObject('MSXML2.ServerXMLHTTP');
  objXMLHTTP.open('GET', link, false);
  objXMLHTTP.send();

  var objADOStream = new ActiveXObject('ADODB.Stream');
  objADOStream.Type = 1;
  objADOStream.Mode = 3;
  objADOStream.Open();
  objADOStream.Write(objXMLHTTP.responseBody);
  objADOStream.Position = 0;

  WScript.ECHO('Saving ...');
  var objFSO = new ActiveXObject('Scripting.FileSystemObject');
  objADOStream.SaveToFile(objFSO.BuildPath(WScript.Arguments(0), objFSO.GetFileName(link)), 2);
  objADOStream.Close();
}
catch(e) {
  if (objIE != null) { objIE.Quit(); }
  WScript.ECHO('Error!');
}
If you go to the link, I'm trying to download the "Service Pack" int he right most box. What happened what in the past, there used to be a Windows and Linux pack like the box in the middle, but nows its one single box and i'm not sure how to adjust the code to key in that box.

Does anyone have any idea? Thank you!

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: jscript issues with downloading a zip from the Web

#2 Post by penpen » 06 Jun 2020 12:48

When checking the webpage, it seems that they are still using the same class names and (most of the) internal structure but inserted an "<tr></tr>". So you should update the number behind the selected "tr"-object (untested):
Change the "getElementsByTagName('tr')[2]" part to "getElementsByTagName('tr')[3]".

Sidenotes:
You may press F-12 when wieving the target webpage to analyze the html-code yourself.
You should also add an "goto :eof" after the "pause"- command to avoid executing the jscript code in the batch interpreter "cmd.exe".


penpen

SIMMS7400
Posts: 539
Joined: 07 Jan 2016 07:47

Re: jscript issues with downloading a zip from the Web

#3 Post by SIMMS7400 » 12 Jun 2020 02:13

Hi Penpen -

Changing to "3" worked and the link is found. But I'm getting an error on the download and can't figure out why.

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: jscript issues with downloading a zip from the Web

#4 Post by penpen » 15 Jun 2020 02:51

I don't see the error you get, so could you copy paste or describe that?


penpen

SIMMS7400
Posts: 539
Joined: 07 Jan 2016 07:47

Re: jscript issues with downloading a zip from the Web

#5 Post by SIMMS7400 » 17 Jun 2020 04:14

Hi PenPen -

When I echo the error, it says "Object Error", but nothing else.

You're able to get the file to download?

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: jscript issues with downloading a zip from the Web

#6 Post by penpen » 17 Jun 2020 12:01

You misunderstood what i wrote above:
I didn't ask you to change the program code to get more info about that error (if that is what you might mean with "When I echo the error".

I simply don't know, what you see on your screen.
That program has multiple "WScript.ECHO"-statements.
Once it reaches the error it might, or might not give any hints.
So the complete output of your program would help to find which lines are candidates for containing the error.
(And don't just double-click on that batch. Open a "cmd.exe"-instance and type in its name, so the window stays open.)


penpen

Post Reply