(view source code of spider.bat as plain text)
@ECHO OFF
:: Check Windows version and command line arguments
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
IF NOT "%~3"=="" GOTO Syntax
IF NOT "%~2"=="" IF /I NOT "%~1"=="/E" GOTO Syntax
IF NOT "%~1"=="" IF /I NOT "%~1"=="/E" GOTO Syntax
:: Localize variables
SETLOCAL
:: Interpret command line arguments
IF /I "%~1"=="/E" (SET ErrOnly=1) ELSE (SET ErrOnly=0)
IF "%ErrOnly%"=="1" (
IF "%~2"=="" (SET ErrType= ) ELSE (SET ErrType=%~2)
)
:: This batch file may generate some stray files that we want to
:: clean up afterwards, so we'll create our own temporary directory
SET Temp=%Temp:"=%
SET MyTemp="%Temp%.\_spider"
MD %MyTemp% 2>NUL
:: Search all HTML files for hyperlinks, suppress error messages
FOR %%? IN (*.htm *.html) DO CALL :Search "%%~f?" 2>NUL
:: Remove our own temporary directory
PUSHD "%Temp%"
RD /S /Q _spider
POPD
:: Done
ENDLOCAL
GOTO:EOF
:Search
PUSHD %MyTemp%
FOR /F "tokens=*" %%A IN ('TYPE "%~1" ^| FIND.EXE /I "<A HREF=" ^| FIND.EXE "http://" ^| CUT.EXE -F:2 -L:1 -D:^'\^^^"^' ^| FIND.EXE "http://"') DO CALL :Check "%~1" "%%~A"
POPD
GOTO:EOF
:Check
SET _html=%1
SET _url=%2
FOR /F "tokens=*" %%x IN ('WGET.EXE --spider --tries=2 --timeout=30 %2 2^>^&1') DO SET line=%%x
IF "%ErrOnly%"=="1" (
IF NOT "%line%"=="200 OK" (
ECHO.%line% | FIND.EXE /I "%ErrType%" >NUL
IF NOT ERRORLEVEL 1 ECHO.%line% %1 %2
)
) ELSE (
ECHO.%line% %1 %2
)
GOTO:EOF
:Syntax
ECHO.
ECHO Spider.bat, Version 0.22 alpha for Windows NT 4 and later
ECHO Display the validity of hyperlinks in a group of locally stored HTML files.
ECHO.
ECHO Usage: SPIDER [ /E [ error# ] ]
ECHO.
ECHO Where: /E forces display of errors only (default is ALL results)
ECHO error# will display errors of this type only (e.g. /E 404)
ECHO.
ECHO Notes: Must be started in the directory where the HTML files are located.
ECHO Uses WGET --spider to check the validity of the hyperlinks; tested
ECHO with WGET that came with ApacheFriends XAMPP for windows Version 1.0
ECHO available at http://www.apachefriends.org/
ECHO Also uses CUT, a compiled version of my CUT.PL script, which is
ECHO available at http://www.robvanderwoude.com/cut.html
ECHO Being an alpha version, and a quick-and-dirty one at that, I can in
ECHO no way guarantee this batch file will work correctly on any computer;
ECHO in fact I can guarantee there are still some bugs that need correction.
ECHO.
ECHO Written by Rob van der Woude to check his own site
ECHO http://www.robvanderwoude.com
page last modified: 2024-04-16; loaded in 0.0091 seconds