1

I have a batch inspired by the reply to this question:

Need to parse out string from HTML document in a batch file

It needed some lite modification to work, because "DOM.Write(x.responseText);" was giving me an error. So here "my version" (I really didn't change it so much)

@if (@CodeSection == @Batch) @then

@echo off
setlocal

set "URL=https://www.some.url"

for /f "delims=" %%I in ('cscript /nologo /e:jscript "%~f0" "%URL%"') do echo %%I

rem // end main runtime
goto :EOF

@end // end batch / begin JScript chimera

var http = WSH.CreateObject("Msxml2.ServerXMLHTTP");
var DOM = WSH.CreateObject("htmlfile");

http.open("GET",WSH.Arguments(0), false);
http.send('');

DOM.write(http.responseText)

var strCountry = DOM.getElementById('country');
WSH.Echo("Country " + strCountry);

var strCitieslink = DOM.getElementById('city').getElementsByTagName('div')(1).getElementsByTagName('div')(2).getElementsByTagName('ul')(0).getElementsByTagName('li');
for (var current = 0; current < strCitieslink.length; ++current) {
    WSH.Echo("City " + current + " link = " + strCitieslink[current].getElementsByTagName("a")(0).getAttribute("href"));
}

It works perfectly except for the fact it deletes itself after the excution and I have no idea of why.

Here some extra infos:

  • I'm using Windows 10 and running the batch from cmd
  • The original "file version" (first code in the answer) works just fine
  • Even the original "http version" (second code) deletes itself (at first I tought it depended to the error)
  • After deletion windows forbids me to create or rename a file using the same name of the deleted one

Any suggestion?

Thanks guys!

P.S.: Sorry for my bad English.

Tarthesos
  • 11
  • 2
  • Do you have any security software that might be flagging it as malware and quarantining it? – Squashman Dec 05 '21 at 01:13
  • Try keep this script opened in some text editor during runtime and see what happen – user2956477 Dec 05 '21 at 01:17
  • @Squashman: I have Avast, but it's configured to ask before taking any actions, because I don't like applications doing things I can't control – Tarthesos Dec 05 '21 at 11:03
  • @user2956477: It was always opened in Visual Studio Code, if it wasn't I had lost it too many times and, to be honest, the first time it was deleted I noticed only because was opened in VSC – Tarthesos Dec 05 '21 at 11:06
  • Try to use Process Monitor to find out what is happening with your file. – user2956477 Dec 05 '21 at 17:53
  • @user2956477: Ok, I'll try. I hope to find a clue – Tarthesos Dec 05 '21 at 18:42
  • @user2956477: Thanks to your suggestion I found Avast sometimes was using a little more CPU. so Squashman was totally right. My script was seen as Malware and put in quanrantine. My fault was not checking the options after the last Avast Update, it appens sometimes that it revert my changes back. – Tarthesos Dec 06 '21 at 21:25
  • @Squashman: You were totally right, at the end i was Avast that was deleting my script. I found that after and update it restored some default behaviour. Thank you for your suggestion! – Tarthesos Dec 06 '21 at 21:29

0 Answers0