JSI Tip 9840. How do I retrieve the source of a web page?


I have scripted GetSource.bat to retrieve the source of a Web page and write it to a file.

This script can also be used if the right-clicking has been disabled, or if viewing source has been prevented.

The syntax for using GetSource.bat is:

GetSource URL FileName

Where:

URL      is the Web page URL, like HTTP://www.JSIINC.COM or HTTP://www.JSIFAQ.com/SUBT/TIP9800/RH9840.htm.

FileName is the file that will contain the URL source, like C:\Folder\FileName.htm or FileName.txt.
GetSource.bat contains:
@echo off
if \{%2\}==\{\} @echo Syntax GetSource URL FileName&goto :EOF
setlocal
if exist "%TEMP%\GetSource.vbs" goto getit
@echo.dim fso, writefile, contents, Filename, objArguments, url>"%TEMP%\GetSource.vbs"
@echo.set fso = CreateObject("Scripting.FileSystemObject") >>"%TEMP%\GetSource.vbs"
@echo.Set objArguments = Wscript.Arguments>>"%TEMP%\GetSource.vbs"
@echo.url=objArguments(0) >>"%TEMP%\GetSource.vbs"
@echo.Filename=objArguments(1) >>"%TEMP%\GetSource.vbs"
@echo.set xmlhttp=createobject("microsoft.xmlhttp") >>"%TEMP%\GetSource.vbs"
@echo.xmlhttp.open "GET", url, False>>"%TEMP%\GetSource.vbs"
@echo.xmlhttp.send>>"%TEMP%\GetSource.vbs"
@echo.contents=xmlhttp.responsetext>>"%TEMP%\GetSource.vbs"
@echo.set writefile = fso.CreateTextFile(FileName, 2) >>"%TEMP%\GetSource.vbs"
@echo.writefile.writeLine contents>>"%TEMP%\GetSource.vbs"
@echo.writefile.close>>"%TEMP%\GetSource.vbs"
:getit 
cscript //nologo "%TEMP%\GetSource.vbs" %1 %2



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish