How to extract data from website?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to extract data from website?

#31 Post by aGerman » 26 May 2017 10:01

I have no idea why conditional compilation is turned off on your machine. Maybe you used some kind of bat2exe nonsense thingy that you didn't tell us or whatever ...

If it doesn't work as hybrid script just use the JScript section as stand-alone.

download.js

Code: Select all

var objIE = null;
try {
  WScript.Echo('Searching link ...');
  objIE = new ActiveXObject('InternetExplorer.Application');
  // objIE.Visible = true;
  objIE.Navigate(WScript.Arguments(0));
  while (objIE.Busy) { WScript.Sleep(100); }
  WScript.Sleep(3000);
  var link = objIE.document.getElementsByClassName('DownloadButtonAd-startDownload gbtnSecondary')[0].getAttribute('href');
  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;

  objIE.Quit();
  objIE = null;

  WScript.Echo('Saving ...');
  var objFSO = new ActiveXObject('Scripting.FileSystemObject');
  objADOStream.SaveToFile(objFSO.BuildPath(WScript.Arguments(1), objFSO.GetFileName(link)), 2);
  objADOStream.Close();
  WScript.Quit(0);
}
catch(e) {
  if (objIE != null) { objIE.Quit(); }
  WScript.Echo('Error!');
  WScript.Quit(1);
}


Now you can call it directly from within your batch code

Code: Select all

::                script path   mediafire site where to find the direct link                 directory where to save the file
cscript //nologo "download.js" "http://www.mediafire.com/file/4tovbku6kcercc7/Speecher.rar" "%userprofile%\Desktop"

PaperTronics
Posts: 118
Joined: 02 Apr 2017 06:11

Re: How to extract data from website?

#32 Post by PaperTronics » 28 May 2017 05:45

Actually I did use a bat2exe converter back when I was just started learning Batch. I didn't know that you could use plugins in Batch files, so the "Advanced Options" in the bat2exe converter impressed me :mrgreen: . I don't use it now tho.

Anyways the code is working.
Is there a way to turn Conditional Compiling on again in my computer??

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to extract data from website?

#33 Post by aGerman » 29 May 2017 10:57

I tried hard to find any reference but all I repeatedly found is how to enable Conditional Compilation in the JScript using

Code: Select all

/*@cc_on @*/
But that isn't any option for a hybrid script because the first line of the script has to be valid code in both Batch and JScript. I still have no clue why Conditional Compilation is disabled for you (or what else could cause this error).

Steffen

PaperTronics
Posts: 118
Joined: 02 Apr 2017 06:11

Re: How to extract data from website?

#34 Post by PaperTronics » 30 May 2017 05:31

Actually even I tried searching about how to turn CC on. All that came up was :

Code: Select all

/*@cc_on @*/


Also aGerman can u send me links of some other of your creations? I'm really looking for some new & fresh content on my blog

Post Reply