批处理脚本获取HTML网站和parsing内容(没有wget,curl或其他外部应用程序)

我只需要使用Windows cmdfunction。 我需要从网站的两个variables/string在批处理脚本中使用它来validation操作。 为了不使它太简单,此网站需要另外authentication。

我发现这个地方:

@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) 

但我不确定是否有可能获得网站的内容,而不是地位的答案,我不知道如何实现网站的authentication。

上面的代码不能正确工作,因为它会一直由于pipe道而产生错误,但是这似乎更接近我所希望parsing的内容。

我只使用过wget从Windows批处理脚本中获取网页内容。 通过JScript使用XHR是一个奇妙的想法!

但是,您正在尝试search的脚本似乎是用于检查Web服务器是否响应,而不是用于获取内容。

通过一些修改,你可以使用它来获取一个网页,并做你需要的任何处理。

 @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);