批处理脚本获得HTML网站和解析的内容(不wget的,卷曲或其他外部应用程序) [英] batch script get html site and parse content (without wget, curl or other external app)

查看:147
本文介绍了批处理脚本获得HTML网站和解析的内容(不wget的,卷曲或其他外部应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要只用CMD窗口functionallity工作。我需要两个瓦尔/字符串从一个网站的batchscript用于验证它的行动。不让它不要太简单本网站需要除了鉴别。

i need to work with windows cmd functionallity only. i need two vars/strings from a website to use in the batchscript for validate actions with it. to not make it not too simple this website needs authentification in addition.

我发现这个地方:

@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 am not shure if it's possible to get the site content this way too instead of status answer and the more i don't know how to implement website authentification to this.

以上code不能正常工作,因为它会产生永诺因为管道的错误,但是这似乎更接近我的分析我希望内容的需求。

the above code does not work correctly as it will allways produce error because of the pipe, but this seemed nearer to my needs of parsing the content i hoped.

任何帮助AP preciated真的。

any help appreciated really.

问候
皮特

推荐答案

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

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

但你要掠夺脚本似乎是用于检查是否为Web服务器响应,而不是获取内容。

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

这篇关于批处理脚本获得HTML网站和解析的内容(不wget的,卷曲或其他外部应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆