Fetch HTML and save it to a file with Windows command line

I'm trying to save the html source of a fetched web page into a file and I want to do this using only the CMD prompt on Windows. I could do this with wget, but that requires using the wget program. Is there any easy way to do this?

3,639 4 4 gold badges 30 30 silver badges 48 48 bronze badges asked Jul 26, 2014 at 21:28 51 1 1 gold badge 1 1 silver badge 6 6 bronze badges

6 Answers 6

You may use a Batch-JScript hybrid script to do that in a very easy way. The JScript support is installed with all Windows versions from XP on.

@if (@CodeSection == @Batch) @then @echo off CScript //nologo //E:JScript "%~F0" "%~1" > "%~N1.html" goto :EOF @end var http = WScript.CreateObject('Msxml2.XMLHTTP.6.0'); http.open("GET", WScript.Arguments.Item(0), false); http.send(); if (http.status == 200) < WScript.StdOut.Write(http.responseText); >else

Save previous code in a .BAT file, for example: GetHtmlCode.bat, and execute it with the web address in the first parameter:

GetHtmlCode.bat "https://stackoverflow.com/questions/24975698/get-code-html-to-a-file-whit-cmd" 

I borrowed previous code from the accepted answer of this question and just did a couple small changes.