Batch script get html site and parse content (without wget, curl or other external app)

I’ve only ever used wget to fetch web content from a Windows batch script. Using an XHR via JScript was a fantastic idea!

But the script you’re trying to plunder appears to be intended for checking whether a web server is responding, not for fetching content.

With some modifications, you can use it to fetch a web page and do whatever processing you need.

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

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

@echo off
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
goto :EOF

echo Usage: %~nx0 URL
echo     for example: %~nx0
echo The URL must be fully qualified, including the http:// or https://
goto :EOF

JScript */
var x=new ActiveXObject("Microsoft.XMLHTTP");"GET",WSH.Arguments(0),true);
while (x.readyState!=4) {WSH.Sleep(50)};

Leave a Comment