Creating Safari Script to recognize when 2 consecutive numbers appear

Hi everyone,

Just for some background, I’m a medical student in the US who needs to take the board examination in order to receive my MD. Unfortunately, COVID-19 has cancelled testing dates for everyone since March. Now the testing centers that are open are only filling every other computer to maintain social distancing. As you can imagine find a date has been nothing short of a shitshow.

I’m taking the exam over two days and since test opening come and go in the blink of an eye, I learned as much as I could about AppleScript to create a script that auto refreshes our testing page and monitor for an open test date. This is what I have at the moment that works to find when a single date has opened.


set openSlot to false

repeat while openSlot is false
	
	clickClassName("calActiveLink", 0)

	tell application "Safari"
		if text in tab 1 of window 1 contains "Schedule an Appointment" then
			display notification "OPEN SLOT AVAILABLE "
			set openSlot to true
		end if
	end tell

	if openSlot is false then
		delay 60
		clickID("masterPage_cphPageBody_btnGoCal")
	end if
	
end repeat

([applescript] tags lower-cased by NG.)

Whenever a test date opens it the class changes from “calInactive” to “calActive”. Each class is also associated with an id and href representing the date (ie. “id = 20200609” “href = 20”).

Since I’m taking the test over 2 days, I’m trying to make it that I only get a notification if there are 2 “calActive” classes with hrefs that are consecutive numbers.

As far as I can tell the href only appears when the date is active so I may not need the “calActive” all together.

Apologies for the long post and thanks in advance for any replies.

Perhaps I misunderstood you, but I think you want to perform a second mouse click depending on the result of the first mouse click. Try it like this:


repeat
	try
		clickClassName("calActiveLink", 0)
		tell application "Safari"
			if text in tab 1 of window 1 contains "Schedule an Appointment" then
				display notification "OPEN SLOT AVAILABLE "
				exit repeat
			end if
		end tell
	end try
	delay 1
end repeat

-- delay 60 -- ?????
clickID("masterPage_cphPageBody_btnGoCal")

or, like this:


clickClassName("calActiveLink", 0)
repeat
	try
		clickID("masterPage_cphPageBody_btnGoCal")
		tell application "Safari" to if text in tab 1 of window 1 contains "Schedule an Appointment" then display notification "OPEN SLOT AVAILABLE "
	on error
		delay 1
	end try
end repeat

Thanks for the reply. To clarify, I’m only trying trying to receive a notification if there are 2 consecutive dates available (ie. June 2nd and either June 1st or June 3rd). This is my best idea thus far

[AppleScript]
to getInputByClass(theClass, num)
tell application “Safari”
do JavaScript “document.getElementsByClassName('” & theClass & “')[” & num & “].innerHTML;” in tab 1 of window 1
end tell
end getInputByClass

to clickID(theId)
tell application “Safari”
do JavaScript “document.getElementById('” & theId & “').click();” in tab 1 of window 1
end tell
end clickID
getInputByClass(“calActiveLink”, “x”)

set opendate to false
set dateresult to getInputByClass(“calActiveLink”, 0)

repeat while opendate is false
getInputByClass(“calActiveLink”, 0)

if dateresult is greater than 0 then
    set opendate to true
    display notification "OPEN SLOT AVAILABLE"
end if

clickID("masterPage_cphPageBody_btnGoCal")
delay 60

end repeat
[/AppleScript]

getInputByClass(“calActiveLink”, x) returns the value of the date available

(ie. if June 4th is the first date available then getInputByClass(“calActiveLink”, 0) returns a value of 4

I can only get it to show single results. Is there a way for getInputByClass(“calActiveLink”) to show all the values of the open dates? Then if any of the dates are consecutive numbers, it’ll set “opendate” in the script to true

Hi. If you want to know if dates are consecutive, you need to realize them as dates and compare them—something along these lines:

set firstID to "20200609"
set secondID to "20200610"
if (date (my format2USdate(firstID))) + 1 * days = (date (my format2USdate(secondID))) then beep --consecutiveness feedback


on format2USdate(this)
	tell this to its text 5 thru 6 & "-" & its text 7 thru 8 & "-" & its text 1 thru 4
end format2USdate

Perhaps you could obtain all the IDs on the page and step through by twos with the above. The problem is that there’s really not enough information to be able to guide you properly. How about example text output from the page?

This (as you have) returns single element number num of the given class:


tell application "Safari"
	do JavaScript "document.getElementsByClassName('" & theClass & "')[" & num & "].innerHTML;" in tab 1 of window 1
end tell

And, this returns all elements of the given class (as list):


tell application "Safari"
    do JavaScript "document.getElementsByClassName('" & theClass & "').innerHTML;" in tab 1 of window 1
end tell

You need, most likely, item -1 and item -2 of the list. Or, item 1 and item 2 of the list.

Sure. I posted it below:

	<tbody>
		<tbody>
December 2020
S M T W T F S
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

Unfortunately, when I try the script below, a result does not return


tell application "Safari"
    do JavaScript "document.getElementsByClassName('" & theClass & "').innerHTML;" in tab 1 of window 1
end tell[/AppleScript]



[quote=KniazidisR]

[quote=medscripter2020]
ie. if June 4th is the first date available then getInputByClass("calActiveLink", 0) returns a value of 4

I can only get it to show single results. Is there a way for getInputByClass("calActiveLink") to show all the values of the open dates? Then if any of the dates are consecutive numbers, it'll set "opendate" in the script to true
[/quote]

This (as you have) returns single element number [b]num[/b] of the  given class:

tell application “Safari”
do JavaScript “document.getElementsByClassName('” & theClass & “')[” & num & “].innerHTML;” in tab 1 of window 1
end tell


And, this returns all elements of the given class (as list):

tell application “Safari”
do JavaScript “document.getElementsByClassName('” & theClass & “').innerHTML;” in tab 1 of window 1
end tell



You need, most likely, item -1 and  item -2 of the list. Or, item 1 and  item 2 of the list.
[/quote]

It appears they already have proper US dates embedded in the links. Try this:

tell application "Safari"'s document 1 to set pageText to its text --or its source, if that doesn't work
do shell script "echo " & pageText's quoted form & " | grep 'showAppoint'  | egrep -o '(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday).+20' "

Thanks for the tip! I tried it the script below and received text back as a response.

tell application "Safari"'s document 1 to set pageText to its source --or its source, if that doesn't work
do shell script "echo " & pageText's quoted form & " | egrep -o 'title=.+href'"

It returns back all the dates between the first and last open dates, active and inactive included. For example, the following was attained from September (active dates: 4, 5, 12, 14, 15, 21, 25, 28).

Given that “href= #” only appears if the date is active and has a numerical value reflective of the date available, I’m having trouble finding the proper syntax to formulate an “if…then” statement to reflect if two href values are +/- 1 from each other, then to return a notification.

"Result:
"title='Friday, September 4, 2020' href='#4'>4</a></td>
<td id=\"20200905\" class=\"calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('05-Sep-2020', '8:00 AM - 5:00 PM|')\" style=\"width:14%;\"><a class='calActiveLink' title='Saturday, September 5, 2020' href='#5'>5</a></td></tr>
<tr><td id=\"20200906\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">6</td>
<td id=\"20200907\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">7</td>
<td id=\"20200908\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">8</td>
<td id=\"20200909\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">9</td>
<td id=\"20200910\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">10</td>
<td id=\"20200911\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">11</td>
<td id=\"20200912\" class=\"calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('12-Sep-2020', '8:00 AM - 5:00 PM|')\" style=\"width:14%;\"><a class='calActiveLink' title='Saturday, September 12, 2020' href='#12'>12</a></td></tr>
<tr><td id=\"20200913\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">13</td>
<td id=\"20200914\" class=\"calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('14-Sep-2020', '8:00 AM - 5:00 PM|')\" style=\"width:14%;\"><a class='calActiveLink' title='Monday, September 14, 2020' href='#14'>14</a></td>
<td id=\"20200915\" class=\"calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('15-Sep-2020', '8:00 AM - 5:00 PM|')\" style=\"width:14%;\"><a class='calActiveLink' title='Tuesday, September 15, 2020' href='#15'>15</a></td>
<td id=\"20200916\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">16</td><td id=\"20200917\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">17</td><td id=\"20200918\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">18</td><td id=\"20200919\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">19</td></tr><tr><td id=\"20200920\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">20</td><td id=\"20200921\" class=\"calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('21-Sep-2020', '8:00 AM - 5:00 PM|')\" style=\"width:14%;\"><a class='calActiveLink' title='Monday, September 21, 2020' href='#21'>21</a></td>
<td id=\"20200922\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">22</td>
<td id=\"20200923\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">23</td>
<td id=\"20200924\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">24</td>
<td id=\"20200925\" class=\"calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('25-Sep-2020', '8:00 AM - 5:00 PM|')\" style=\"width:14%;\"><a class='calActiveLink' title='Friday, September 25, 2020' href='#25'>25</a></td>
<td id=\"20200926\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">26</td></tr><tr>
<td id=\"20200927\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">27</td>
<td id=\"20200928\" class=\"calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('28-Sep-2020', '8:00 AM - 5:00 PM|')\" style=\"width:14%;\"><a class='calActiveLink' title='Monday, September 28, 2020' href"

I saved the datas from message #6 in a text file named “appointments.txt” on my desktop.
Then I ran :

set p2d to path to desktop as string
set myFile to (p2d & "appointments.txt") as «class furl»
set myDatas to read myFile as «class utf8»
set myKey to quote & "calActive" & quote
set enListe to my decoupe(myDatas, myKey)
set lesBons to {}
repeat with i from 2 to count enListe
	set end of lesBons to (paragraph -1 of item (i - 1) of enListe) & myKey & paragraph 1 of item i of enListe
end repeat

log lesBons

set enTexte to my recolle(lesBons, linefeed)

#=====

on decoupe(t, d)
	local oTIDs, l
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set l to text items of t
	set AppleScript's text item delimiters to oTIDs
	return l
end decoupe

#=====

on recolle(l, d)
	local oTIDs, t
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end recolle

#=====
(*
replaces every occurences of d1 by d2 in the text t
*)
on remplace(t, d1, d2)
	local oTIDs, l
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d1}
	set l to text items of t
	set AppleScript's text item delimiters to d2
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end remplace

#=====

I got a list which is not easy to read:

(*<td id="20201204" class="calActive" align="center" onclick="IWRSeatAvail.showAppointmentDate('04-Dec-2020', '9:00 AM - 6:00 PM|')" style="width:14%;"><a class="calActiveLink" title="Friday, December 4, 2020" href="#4">4</a></td>, <td id="20201207" class="calActive" align="center" onclick="IWRSeatAvail.showAppointmentDate('07-Dec-2020', '9:00 AM - 6:00 PM|')" style="width:14%;"><a class="calActiveLink" title="Monday, December 7, 2020" href="#7">7</a></td>, <td id="20201214" class="calActive" align="center" onclick="IWRSeatAvail.showAppointmentDate('14-Dec-2020', '9:00 AM - 6:00 PM|')" style="width:14%;"><a class="calActiveLink" title="Monday, December 14, 2020" href="#14">14</a></td>, <td id="20201218" class="calActive" align="center" onclick="IWRSeatAvail.showAppointmentDate('18-Dec-2020', '9:00 AM - 6:00 PM|')" style="width:14%;"><a class="calActiveLink" title="Friday, December 18, 2020" href="#18">18</a></td>, <td id="20201221" class="calActive" align="center" onclick="IWRSeatAvail.showAppointmentDate('21-Dec-2020', '9:00 AM - 6:00 PM|')" style="width:14%;"><a class="calActiveLink" title="Monday, December 21, 2020" href="#21">21</a></td>, <td id="20201226" class="calActive" align="center" onclick="IWRSeatAvail.showAppointmentDate('26-Dec-2020', '9:00 AM - 6:00 PM|')" style="width:14%;"><a class="calActiveLink" title="Saturday, December 26, 2020" href="#26">26</a></td>, <td id="20201228" class="calActive" align="center" onclick="IWRSeatAvail.showAppointmentDate('28-Dec-2020', '9:00 AM - 6:00 PM|')" style="width:14%;"><a class="calActiveLink" title="Monday, December 28, 2020" href="#28">28</a></td>*)

and I got a text object which may be helpful:

"<td id=\"20201204\" class=\"calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('04-Dec-2020', '9:00 AM - 6:00 PM|')\" style=\"width:14%;\"><a class=\"calActiveLink\" title=\"Friday, December 4, 2020\" href=\"#4\">4</a></td>
<td id=\"20201207\" class=\"calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('07-Dec-2020', '9:00 AM - 6:00 PM|')\" style=\"width:14%;\"><a class=\"calActiveLink\" title=\"Monday, December 7, 2020\" href=\"#7\">7</a></td>
<td id=\"20201214\" class=\"calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('14-Dec-2020', '9:00 AM - 6:00 PM|')\" style=\"width:14%;\"><a class=\"calActiveLink\" title=\"Monday, December 14, 2020\" href=\"#14\">14</a></td>
<td id=\"20201218\" class=\"calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('18-Dec-2020', '9:00 AM - 6:00 PM|')\" style=\"width:14%;\"><a class=\"calActiveLink\" title=\"Friday, December 18, 2020\" href=\"#18\">18</a></td>
<td id=\"20201221\" class=\"calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('21-Dec-2020', '9:00 AM - 6:00 PM|')\" style=\"width:14%;\"><a class=\"calActiveLink\" title=\"Monday, December 21, 2020\" href=\"#21\">21</a></td>
<td id=\"20201226\" class=\"calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('26-Dec-2020', '9:00 AM - 6:00 PM|')\" style=\"width:14%;\"><a class=\"calActiveLink\" title=\"Saturday, December 26, 2020\" href=\"#26\">26</a></td>
<td id=\"20201228\" class=\"calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('28-Dec-2020', '9:00 AM - 6:00 PM|')\" style=\"width:14%;\"><a class=\"calActiveLink\" title=\"Monday, December 28, 2020\" href=\"#28\">28</a></td>"

I guess that some extraneous cleaning may be applied but I don’t know what may be dropped and what must be preserved.
For instance if I add two instructions to get:

log lesBons

set enTexte to my recolle(lesBons, linefeed)
set enTexte to my remplace(enTexte, "<td id=" & quote, "")
set enTexte to my remplace(enTexte, quote & " class=" & quote, tab)

the returned text become:

"20201204	calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('04-Dec-2020', '9:00 AM - 6:00 PM|')\" style=\"width:14%;\"><a class=\"calActiveLink\" title=\"Friday, December 4, 2020\" href=\"#4\">4</a></td>
20201207	calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('07-Dec-2020', '9:00 AM - 6:00 PM|')\" style=\"width:14%;\"><a class=\"calActiveLink\" title=\"Monday, December 7, 2020\" href=\"#7\">7</a></td>
20201214	calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('14-Dec-2020', '9:00 AM - 6:00 PM|')\" style=\"width:14%;\"><a class=\"calActiveLink\" title=\"Monday, December 14, 2020\" href=\"#14\">14</a></td>
20201218	calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('18-Dec-2020', '9:00 AM - 6:00 PM|')\" style=\"width:14%;\"><a class=\"calActiveLink\" title=\"Friday, December 18, 2020\" href=\"#18\">18</a></td>
20201221	calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('21-Dec-2020', '9:00 AM - 6:00 PM|')\" style=\"width:14%;\"><a class=\"calActiveLink\" title=\"Monday, December 21, 2020\" href=\"#21\">21</a></td>
20201226	calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('26-Dec-2020', '9:00 AM - 6:00 PM|')\" style=\"width:14%;\"><a class=\"calActiveLink\" title=\"Saturday, December 26, 2020\" href=\"#26\">26</a></td>
20201228	calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('28-Dec-2020', '9:00 AM - 6:00 PM|')\" style=\"width:14%;\"><a class=\"calActiveLink\" title=\"Monday, December 28, 2020\" href=\"#28\">28</a></td>"

which become easy to filter because the “compact” dates are perfectly visible.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 9 mai 2020 23:13:02

This should return all elements of “calActiveLink” class. Then you can parse dates from list and compare. Most likely, you need item -2 and item -1 of theElements list:


set theElements to {}
set i to 0

tell application "Safari"
	activate
	repeat
		set theScript to "document.getElementsByClassName('calActiveLink')['" & i & "'].innerHTML;"
		set element to (do JavaScript theScript in first tab of first window)
		try
			set end of theElements to element
			set i to i + 1
		on error
			exit repeat
		end try
	end repeat
end tell
return theElements

I’m not sure why you changed the example I provided to include text through “href.” My grep narrowed your text down to just the target dates:
[format]Friday, December 4, 2020
Monday, December 7, 2020
Monday, December 14, 2020
Friday, December 18, 2020
Monday, December 21, 2020
Saturday, December 26, 2020
Monday, December 28, 2020[/format]

Even though they are properly formatted, you still have to convert dates to AppleScript date objects for comparison, as previously noted.

tell application "Safari"'s document 1 to set pageText to source
set appointments to (do shell script "echo " & pageText's quoted form & " | tr " & return & space & quote & linefeed & quote & " | grep 'showAppoint'  | egrep -o '(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday).+20' ")'s paragraphs
set {nonConsec, consec} to {{}, {}}
repeat with counter from 1 to (count appointments) - 1
	set {compOne, compTwo} to {date (appointments's item counter), date (appointments's item (counter + 1))}
	if compOne + 1 * days = compTwo then
		set consec's end to {compOne's date string, "—", compTwo's date string} & return as text
	else
		set nonConsec's end to {compOne's date string, "—", compTwo's date string} & return as text
	end if
end repeat
if not consec = {} then
	display dialog consec as text with title ":)"
else
	say "Only nonconsecutive slots found"
	display dialog nonConsec as text with title ":("
end if

–Edited to report nonconsecutive outcomes, enforce line endings, and remove references to things made impossible by further edits to the thread

I apologize but I have no idea about were must b added the m in line2
I tried:

set appointments to (do shell script "echo " & pageText's quoted form & " | grep 'showAppoint' | egrep -o '(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday).+20' ")'s paragraphs

but it’s clearly wrong.

What need to extract formatted Applescript dates,
extracting “20201204
20201207
20201208
20201214
20201218
20201219
20201221
20201226
20201228
20201229
20201231
20210101”
is perfect to compare dates and, for non English users, it’s simpler than comparing English AppleScript’s dates.

set someDates to paragraphs of "20201204
20201207
20201208
20201214
20201218
20201219
20201221
20201226
20201228
20201229
20201231
20210101"
set consecutives to {}
repeat with i from 1 to (count someDates) - 1
	set iso1 to item i of someDates
	set iso2 to item (i + 1) of someDates
	if (my ISOtodate(iso1)) + 1 * days = my ISOtodate(iso2) then
		set end of consecutives to iso1 & tab & iso2
	end if
end repeat
return consecutives


on ISOtodate(iso)
	set {theYear, theMonth, theDay} to {text 1 thru 4 of iso, text 5 thru 6 of iso, text 7 thru 8 of iso}
	set aDate to date ("1/1/1")
	set year of aDate to theYear
	set month of aDate to theMonth
	set day of aDate to theDay
	return aDate
end ISOtodate

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 11 mai 2020 09:44:58

Yvan, I already exemplified that method in post 4 with the limited info available. The OP, who is from the US, is asking about data already in our date string spec, so it’s easier to use the extant format, although it would not test properly on your French system, unless you change your date setup. The m goes at showAppoint’s end, within the single quotes, like ‘showAppoint m’ except without the space. I can’t display it properly without it being detected in the pattern. At this point, it isn’t worth using this thread as a test. The quoting in post #10 introduced a secondary pattern.

Hi Marc,

Thank you for the script. Unfortunately, when “its source” is replaced with “text” then the following error appears:
“error “Can’t make quoted form of text into type Unicode text.” number -1700 from quoted form of text to Unicode text”

When “its source” remains intact and runs, it states “only nonconsecutive slots found” even when there are consecutive slots available.

Below are the dates it was tested on:

<table id="masterPage_cphPageBody_calSeatSelectionCalendar_9" title="Calendar for September 2020" cellspacing="0" cellpadding="2" border="0" style="border-width:1px;border-style:solid;border-collapse:collapse;margin:0 0 auto 0;">
		<tbody><tr><td colspan="7" style="background-color:Silver;"><table class="calTitleStyle" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;">
			<tbody><tr><td align="center" style="width:70%;" nowrap="nowrap"><caption style="text-align:center;display:block;">September 2020</caption></td></tr>
		</tbody></table></td></tr><tr><th class="calDayHeader" align="center" abbr="Sunday" scope="col">S</th>
<th class="calDayHeader" align="center" abbr="Monday" scope="col">M</th>
<th class="calDayHeader" align="center" abbr="Tuesday" scope="col">T</th>
<th class="calDayHeader" align="center" abbr="Wednesday" scope="col">W</th>
<th class="calDayHeader" align="center" abbr="Thursday" scope="col">T</th>
<th class="calDayHeader" align="center" abbr="Friday" scope="col">F</th><th class="calDayHeader" align="center" abbr="Saturday" scope="col">S</th></tr>

<tr><td id="20200830inactivemonth" class="calInactive" align="center" style="width:14%;"></td>
<td id="20200831inactivemonth" class="calInactive" align="center" style="width:14%;"></td>
<td id="20200901" class="calInactive" align="center" style="width:14%;">1</td><td id="20200902" class="calInactive" align="center" style="width:14%;">2</td>
<td id="20200903" class="calInactive" align="center" style="width:14%;">3</td><td id="20200904" class="calActive" align="center" onclick="IWRSeatAvail.showAppointmentDate('04-Sep-2020', '9:00 AM - 6:00 PM|')" style="width:14%;"><a class="calActiveLink" title="Friday, September 4, 2020" href="#4">4</a></td>
<td id="20200905" class="calActive" align="center" onclick="IWRSeatAvail.showAppointmentDate('05-Sep-2020', '9:00 AM - 6:00 PM|')" style="width:14%;"><a class="calActiveLink" title="Saturday, September 5, 2020" href="#5">5</a></td></tr>
<tr><td id="20200906" class="calInactive" align="center" style="width:14%;">6</td>
<td id="20200907" class="calInactive" align="center" style="width:14%;">7</td>
<td id="20200908" class="calInactive" align="center" style="width:14%;">8</td>
<td id="20200909" class="calInactive" align="center" style="width:14%;">9</td>
<td id="20200910" class="calInactive" align="center" style="width:14%;">10</td>
<td id="20200911" class="calInactive" align="center" style="width:14%;">11</td>
<td id="20200912" class="calActive" align="center" onclick="IWRSeatAvail.showAppointmentDate('12-Sep-2020', '9:00 AM - 6:00 PM|')" style="width:14%;"><a class="calActiveLink" title="Saturday, September 12, 2020" href="#12">12</a></td></tr><tr><td id="20200913" class="calInactive" align="center" style="width:14%;">13</td><td id="20200914" class="calActive" align="center" onclick="IWRSeatAvail.showAppointmentDate('14-Sep-2020', '9:00 AM - 6:00 PM|')" style="width:14%;"><a class="calActiveLink" title="Monday, September 14, 2020" href="#14">14</a></td>
<td id="20200915" class="calInactive" align="center" style="width:14%;">15</td><td id="20200916" class="calInactive" align="center" style="width:14%;">16</td><td id="20200917" class="calInactive" align="center" style="width:14%;">17</td>
<td id="20200918" class="calInactive" align="center" style="width:14%;">18</td>
<td id="20200919" class="calInactive" align="center" style="width:14%;">19</td></tr>
<tr><td id="20200920" class="calInactive" align="center" style="width:14%;">20</td>
<td id="20200921" class="calActive" align="center" onclick="IWRSeatAvail.showAppointmentDate('21-Sep-2020', '9:00 AM - 6:00 PM|')" style="width:14%;"><a class="calActiveLink" title="Monday, September 21, 2020" href="#21">21</a></td>
<td id="20200922" class="calInactive" align="center" style="width:14%;">22</td>
<td id="20200923" class="calInactive" align="center" style="width:14%;">23</td>
<td id="20200924" class="calInactive" align="center" style="width:14%;">24</td>
<td id="20200925" class="calActive" align="center" onclick="IWRSeatAvail.showAppointmentDate('25-Sep-2020', '9:00 AM - 6:00 PM|')" style="width:14%;"><a class="calActiveLink" title="Friday, September 25, 2020" href="#25">25</a></td><td id="20200926" class="calInactive" align="center" style="width:14%;">26</td></tr>
<tr><td id="20200927" class="calInactive" align="center" style="width:14%;">27</td><td id="20200928" class="calActive" align="center" onclick="IWRSeatAvail.showAppointmentDate('28-Sep-2020', '9:00 AM - 6:00 PM|')" style="width:14%;"><a class="calActiveLink" title="Monday, September 28, 2020" href="#28">28</a></td>
<td id="20200929" class="calInactive" align="center" style="width:14%;">29</td>
<td id="20200930" class="calInactive" align="center" style="width:14%;">30</td>
<td id="20201001inactivemonth" class="calInactive" align="center" style="width:14%;"></td>
<td id="20201002inactivemonth" class="calInactive" align="center" style="width:14%;"></td>
<td id="20201003inactivemonth" class="calInactive" align="center" style="width:14%;"></td></tr><tr><td id="20201004inactivemonth" class="calInactive" align="center" style="width:14%;"></td>
<td id="20201005inactivemonth" class="calInactive" align="center" style="width:14%;"></td>
<td id="20201006inactivemonth" class="calInactive" align="center" style="width:14%;"></td>
<td id="20201007inactivemonth" class="calInactive" align="center" style="width:14%;"></td>
<td id="20201008inactivemonth" class="calInactive" align="center" style="width:14%;"></td>
<td id="20201009inactivemonth" class="calInactive" align="center" style="width:14%;"></td>
<td id="20201010inactivemonth" class="calInactive" align="center" style="width:14%;"></td></tr>
	</tbody></table>

The reason I changed it to “href” is because it filtered out more text. When I ran the original script this is what I receive as the result:

"Sunday\" scope=\"col\">S</th><th class=\"calDayHeader\" align=\"center\" abbr=\"Monday\" scope=\"col\">M</th><th class=\"calDayHeader\" align=\"center\" abbr=\"Tuesday\" scope=\"col\">T</th><th class=\"calDayHeader\" align=\"center\" abbr=\"Wednesday\" scope=\"col\">W</th><th class=\"calDayHeader\" align=\"center\" abbr=\"Thursday\" scope=\"col\">T</th><th class=\"calDayHeader\" align=\"center\" abbr=\"Friday\" scope=\"col\">F</th><th class=\"calDayHeader\" align=\"center\" abbr=\"Saturday\" scope=\"col\">S</th></tr><tr><td id=\"20200531inactivemonth\" class=\"calInactive\" align=\"center\" style=\"width:14%;\"></td><td id=\"20200601\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">1</td><td id=\"20200602\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">2</td><td id=\"20200603\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">3</td><td id=\"20200604\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">4</td><td id=\"20200605\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">5</td><td id=\"20200606\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">6</td></tr><tr><td id=\"20200607\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">7</td><td id=\"20200608\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">8</td><td id=\"20200609\" class=\"calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('09-Jun-2020', '8:30 AM - 5:30 PM|')\" style=\"width:14%;\"><a class='calActiveLink' title='Tuesday, June 9, 2020' href='#9'>9</a></td><td id=\"20200610\" class=\"calActive\" align=\"center\" onclick=\"IWRSeatAvail.showAppointmentDate('10-Jun-2020', '8:30 AM - 5:30 PM|')\" style=\"width:14%;\"><a class='calActiveLink' title='Wednesday, June 10, 2020' href='#10'>10</a></td><td id=\"20200611\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">11</td><td id=\"20200612\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">12</td><td id=\"20200613\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">13</td></tr><tr><td id=\"20200614\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">14</td><td id=\"20200615\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">15</td><td id=\"20200616\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">16</td><td id=\"20200617\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">17</td><td id=\"20200618\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">18</td><td id=\"20200619\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">19</td><td id=\"20200620\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">20</td></tr><tr><td id=\"20200621\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">21</td><td id=\"20200622\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">22</td><td id=\"20200623\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">23</td><td id=\"20200624\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">24</td><td id=\"20200625\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">25</td><td id=\"20200626\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">26</td><td id=\"20200627\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">27</td></tr><tr><td id=\"20200628\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">28</td><td id=\"20200629\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">29</td><td id=\"20200630\" class=\"calInactive\" align=\"center\" style=\"width:14%;\">30</td><td id=\"20200701inactivemonth\" class=\"calInactive\" align=\"center\" style=\"width:14%;\"></td><td id=\"20200702inactivemonth\" class=\"calInactive\" align=\"center\" style=\"width:14%;\"></td><td id=\"20200703inactivemonth\" class=\"calInactive\" align=\"center\" style=\"width:14%;\"></td><td id=\"20200704inactivemonth\" class=\"calInactive\" align=\"center\" style=\"width:14%;\"></td></tr><tr><td id=\"20200705inactivemonth\" class=\"calInactive\" align=\"center\" style=\"width:14%;\"></td><td id=\"20200706inactivemonth\" class=\"calInactive\" align=\"center\" style=\"width:14%;\"></td><td id=\"20200707inactivemonth\" class=\"calInactive\" align=\"center\" style=\"width:14%;\"></td><td id=\"20200708inactivemonth\" class=\"calInactive\" align=\"center\" style=\"width:14%;\"></td><td id=\"20200709inactivemonth\" class=\"calInactive\" align=\"center\" style=\"width:14%;\"></td><td id=\"20200710inactivemonth\" class=\"calInactive\" align=\"center\" style=\"width:14%;\"></td><td id=\"2020"

The discrepancy between our results appears to be a line ending difference. I updated my code in post 12.

Hi Marc,

Apologies for the late reply. It worked! Thanks so much for your help