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

前端 未结 3 1473
我寻月下人不归
我寻月下人不归 2020-12-04 01:16

For my new program I want to echo the code of a webpage. I searched on google and Stack Overflow but didn´t found something like this. I do not want to use external programs

相关标签:
3条回答
  • 2020-12-04 01:45

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

    In Linux you can use GET google.com.

    0 讨论(0)
  • 2020-12-04 01:45

    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.

    0 讨论(0)
  • 2020-12-04 01:56

    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.

    0 讨论(0)
提交回复
热议问题