Introduction
Sometimes it is important to check if a web page contains a particular code ot text. One example of this is for testing a webring. A webring will break if just one site in it does not carry the code.
This page looks at various methods of:
Stepping through a list of URLs and fetching the page code.
Searching the page for the appropriate code.
Writing the results to the screen and/or a file.
In these examples I will be using an edited version of the Onionring, webri.ng and Webringu webrings I made.
Some Statistics
In May 2026, I belong to 36 webrings. What I found disappointing is of these 36 webrings only 3 (8%) are fully navigable, ie I can start with the webring widget on my page and follow the sites around to get back to my own page. It is disappointing, but life happens, people close their sites, update the pages and no longer want to bother with the webring widget and so on. Are they worth bothering with at all? Of course they are. AWStats says around 800 visitors a month use the webrings page as an entry and exit point, Webalizer says around 1,200.
Some other statistics. Of the 36 webrings, 20 (55%) use my homepage as the link, 14 (39%) go to the site webring page, and 2 go to other pages. The 36 webrings, use 22 different webring systems, the most numerous being Onionring (13 or 36%) and webri.ng (3 or 8%).
This mixture of landing pages just on my site creates a problem for webring owners checking if their webring code has been added properly or has been never added, removed, or the page changed.
In a perfect world, a webring owner could just get the page the member site's webring widget is on by reading Onionring's variable.js file, from webri.ng's sites information, or from Webringu's member variable. No one lives in a perfect world, so a webring owner needs to keep a list of where on the member sites their webring widget code exists.
A webring owner could keep their own list of the pages where the code is on the various sites. A simple text file with just a single URL on a line will do, but you can get as fancy as you like, JSON (JavaScript Object Notation) or CSV (Comma-Separated Values, but you can use any separator you like) format.
In the following code, the list of websites and the pages the webring widget code is on, is part of the program. I look for the string computering/onionring-variables.js in both scripts, and that needs to be changed to something unique for each webring,
Batch File
Batch files can be very powerful and useful but can be difficult to write especially as Windows was missing some important utilities. Among them was cURL, a tool for transferring data with URLs, which was not introduced until 2018. Batch files cannot use arrays, but it can use indexed variables which can act in the same way.
The following example steps through a list of websites, for each site it uses the curl command to get a copy of the web page, the findstr command to search for the webring code in that page, then writes the information to a file.
The program works because the findstr command changes the variable errorlevel to either 0 if the text is found or 1 if it is not.
The batch file uses just three web sites, Example and Ray's Miscellany Home do not contain the webring code, but Ray's Miscellany Webrings does.
If you would like to explore this code, please copy and paste the code with a .bat extension.
@echo off
setlocal enabledelayedexpansion
REM Configuration
set sitename[0]=Example
set siteURL[0]=https://example.com/index.html
set sitename[1]=Ray's Miscellany Home
set siteURL[1]=https://brisray.com/index.html
set sitename[2]=Ray's Miscellany Webrings
set siteURL[2]=https://brisray.com/utils/webrings.htm
set searchtext=computering/onionring-variables.js
REM Get the webpages
REM curl -s disables progress meter, -L follows redirects
FOR %%G IN (0,1,2) DO (
curl -s -L !siteURL[%%G]! > %TEMP%\webpage.txt
findstr /C:%SEARCH_TEXT% %TEMP%\webpage.txt >nul
IF !errorlevel!==0 (
set result=found
) else (
set result=not found
)
echo !sitename[%%G]! - !siteURL[%%G]! - !result! >> checkURLs.txt
)
setlocal
del %TEMP%\webpage.txt
After the batch file has run, the output file, checkURLs.txt, contains:
Example - https://example.com/index.html - not found Ray's Miscellany Home - https://brisray.com/index.html - not found Ray's Miscellany Webrings - https://brisray.com/utils/webrings.htm - found
Of course you can change the line
echo !sitename[%%G]! - !siteURL[%%G]! - !result! >> checkURLs.txt
to
echo !sitename[%%G]!,!siteURL[%%G]!,!result! >> checkURLs.csv
and the file should open properly in any spreadsheet program.
PowerShell Script
This PowerShell script does the same as the batch file script, it goes to the website URL and checks if the webring widget code is present. It then writes the result to a CSV file, which of course can be opened in a spreadsheet program or as plain text.
If you would like to explore this code, please copy and paste the code with a .ps1 extension.
$sitename = @("Example","Ray's Miscellany Homepage","Ray's Miscellany Webrings")
$siteurl = @("https://example.com/","https://brisray.com/index.htm","https://brisray.com/utils/webrings.htm")
$searchtext="computering/onionring-variables.js"
$sitelist = $PSScriptRoot + "\ring-members.csv"
"Site Name, Site URL, Code Found" | Out-File -FilePath $sitelist
$length = $siteurl.Length - 1
for ($i = 0; $i -le $length; $i++){
$htmlContent = Invoke-WebRequest $siteurl[$i]
$posn = $htmlContent.tostring().IndexOf($searchtext)
if ($posn -ge 0) {
$result="found"
} else {
$result="not found"
}
Add-Content -Path $sitelist -value "$($sitename[$i]),$($siteurl[$i]),$result"
}
After the PowerShell script has run, the output file, ring-members.csv, contains:
Site Name, Site URL, Code Found Example,https://example.com/,not found Ray's Miscellany Homepage,https://brisray.com/index.htm,not found Ray's Miscellany Webrings,https://brisray.com/utils/webrings.htm,found
Sources & Resources
CURL.exe - SS64
Errorlevel and Exit codes - SS64
Errorlevels - Rob van der Woude's Scripting Pages
Invoke-RestMethod - Microsoft Learn
Invoke-WebRequest - Microsoft Learn
Invoke-WebRequest - SS64
Run cURL Commands in Windows 11 - Windows Digitals