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.