Package script get html site and content parsing (without wget, curl or other external application)

I need to work only with cmd functions. I need two vars / strings from a website to use in batchscript to check actions with it. In order not to make it too easy, this site needs authentication.

I found this somewhere:

@set @x=0 /*
:: ChkHTTP.cmd
@echo off
setlocal
set "URL=http://www.google.com"
cscript /nologo /e:jscript "%~f0" %URL% | find "200" > nul
if %ErrorLevel% EQU 0 (
echo Web server ok % Put your code here %
) else (
echo Web server error reported
)
goto :EOF

JScript */
var x=new ActiveXObject("Microsoft.XMLHTTP");
x.open("GET",WSH.Arguments(0));x.send();
while (x.ReadyState!=4) {WSH.Sleep(50)};
WSH.Echo(x.status)

But I’m not sure if it’s possible to get the site’s content this way, instead of responding to the status, and the more I don’t know how to implement site authentication.

The above code doesn’t work correctly, as it always causes an error due to the pipe, but this seemed closer to my needs in analyzing the content I was hoping for.

+3
1

- wget - Windows script. XHR JScript !

script, , , , -, .

- .

@if (@a==@b) @end /*

:: fetch.bat <url>
:: fetch a web page

@echo off
setlocal
if "%~1"=="" goto usage
echo "%~1" | findstr /i "https*://" >NUL || goto usage

set "URL=%~1"
for /f "delims=" %%I in ('cscript /nologo /e:jscript "%~f0" "%URL%"') do (
    rem process the HTML line-by-line
    echo(%%I
)
goto :EOF

:usage
echo Usage: %~nx0 URL
echo     for example: %~nx0 http://www.google.com/
echo;
echo The URL must be fully qualified, including the http:// or https://
goto :EOF

JScript */
var x=new ActiveXObject("Microsoft.XMLHTTP");
x.open("GET",WSH.Arguments(0),true);
x.setRequestHeader('User-Agent','XMLHTTP/1.0');
x.send('');
while (x.readyState!=4) {WSH.Sleep(50)};
WSH.Echo(x.responseText);
+5

Source: https://habr.com/ru/post/1649408/


All Articles