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 like URL2FILE or something like this.
            Asked
            
        
        
            Active
            
        
            Viewed 3,735 times
        
    0
            
            
        - 
                    im not 100% sure this is possible on windows without something like python. – TehTris May 06 '14 at 18:24
- 
                    possible duplicate of [Open a URL without using a browser from a batch file](http://stackoverflow.com/questions/20782734/open-a-url-without-using-a-browser-from-a-batch-file) – user123444555621 May 06 '14 at 18:26
3 Answers
0
            
            
        So you want to display the source code of a webpage in the console line?
In Linux you can use GET google.com.
 
    
    
        Eric Random
        
- 158
- 9
0
            
            
        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.
- 
                    It only opens google.com in chrome, not the HTML Code in the Batch file. – user3608791 May 08 '14 at 14:51
- 
                    The program send the keys used in IExplorer to show the source HTML code: Alt-V and S. You may change those keys by the ones used in Chrome... – Aacini May 08 '14 at 15:36
0
            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.
 
    
    
        MC ND
        
- 69,615
- 8
- 84
- 126
- 
                    It closes instatly when I start it with a second Batch file. (I am a noob at hybrid files) – user3608791 May 08 '14 at 14:52
- 
                    @user3608791, there is no difference from a normal batch file. Does it run when directly called from command line? – MC ND May 08 '14 at 15:55
- 
                    
- 
                    @user3608791, from command line you type `callurl.cmd "http://www.google.com"` and it disappears? – MC ND May 08 '14 at 16:28
- 
                    
- 
                    @user3608791, there is nothing in the code to make it dissapear. The only thing that can happen is that you do not get a HTTP 200 code and the script directly exits. As indicated, there is no error check, just an skeleton. Add code to know what the response is. – MC ND May 08 '14 at 18:01
- 
                    
 
     
    