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
So you want to display the source code of a webpage in the console line?
In Linux you can use GET google.com
.
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.
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.