Is it possible to display the HTML Code of a webpage in a batch file?

我的梦境 提交于 2019-11-27 15:56:53

This code is from a previous question that only needed to do the query to the server (linked in comments) with the "display" of the page source code added.

@if (@This==@IsBatch) @then
@echo off
rem **** batch zone *********************************************************

    setlocal enableextensions disabledelayedexpansion

    rem Batch file will delegate all the work to the script engine 
    if not "%~1"=="" (
        cscript //E:JScript "%~dpnx0" %1
    )

    rem End of batch area. Ensure batch ends execution before reaching
    rem javascript zone
    exit /b

@end
// **** Javascript zone *****************************************************

    // Instantiate the needed component to make url queries
    var http = WScript.CreateObject('Msxml2.XMLHTTP.6.0');

    // Retrieve the url parameter
    var url = WScript.Arguments.Item(0)

    // Make the request

    http.open("GET", url, false);
    http.send();

    // If we get a OK from server (status 200), echo data to console

    if (http.status === 200) WScript.StdOut.Write(http.responseText);

    // All done. Exit
    WScript.Quit(0);

It is just an hybrid batch/javascript file. Saved as callurl.cmd and called as callurl "http://www.google.es" it will do what you ask for. No error check appart from correct response, no post, just a skeleton.

So you want to display the source code of a webpage in the console line?

In Linux you can use GET google.com.

Aacini

The Batch file below display in the screen the HTML Code of the webpage given in the parameter, so I think it is a solution to this topic.

@if (@CodeSection == @Batch) @then

@echo off
rem Start explorer with the web page and wait for it to initialize
start "" Explorer.exe %1
timeout /T 5 > NUL
rem Send to Explorer: Alt-V (View tab)...
CScript //nologo //E:JScript "%~F0" "%%V"
timeout /T 1 > NUL
rem ... followed by S (Source)
CScript //nologo //E:JScript "%~F0" "S"
goto :EOF

@end

WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));

Use previous program this way:

test.bat http://www.google.com

For further details, see this post.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!