Applescript to open webpage from list, search for "text"

hi guys, its me, doritos guy, I've laid off of the doritos for a while, twas given me stomach problems. you know when you eat 10 family size bags a day it might cause a problem, any-who

i appreciated the help from last time when i was trying to script something, now i just have to try to understand some hebrew lettering and sounds for phase 2 of that project.

i know it would be a combination of these two other discussions

Apple Automator to view a list of URLs fr… - Apple Community (i got this one to work for me)
Find text in webpage and email notificati… - Apple Community

basically something like this

Open webpages one at a time from list in txt file
when webpage is loaded, then search for "text"
if "text" is not found
then
close tab, open next URL in list
if "text" is found
then
copy URL to a text file or alert somehow.
once url is copied and saved
then
close tab, open next url in list
repeat

this is what i pieced together from these links

on run {input, parameters}  
     read (item 1 of input)  
     set ps to paragraphs of the result  
     set tot to count ps  
     tell application "Safari"  
          reopen  
          activate  
     end tell  
     repeat with i from 1 to tot  
          set p to item i of ps  
          if p is not "" then  
               try  
                    tell application "Safari"  
                         tell front window  
                              set r to make new tab with properties {URL:p}  
                              set current tab to r  
                              delay 1  
                              if i = tot then exit repeat  
                              repeat  
                                   delay 1  

if text in webpage contains "search text" then
                              copy URL to text file
                    end if
if text in webpage does not contain "search text" then
close tab





                                   get URL of r  
                              end repeat  
                         end tell  
                    end tell  
             end try  
          end if  
     end repeat  
end run  

---------- Post updated at 01:26 AM ---------- Previous update was at 01:12 AM ----------

just realized that i posted this in a shell scripting area, need to move

---------- Post updated at 01:27 AM ---------- Previous update was at 01:26 AM ----------

just realized that i placed this in a shell scripting area, need to move or delete

For the second part of your code, test this...

tell application "Safari"
	activate

        --the source code of current Tab
	set sourceOfTab to source of front document

	set urlOfTab to URL of front document

	if sourceOfTab contains "your text" then

                --copy of the url in textFile
		do shell script "echo " & urlOfTab & " >> ~/text.txt"
	else
		close current tab of front window
	end if
end tell

Perfect, searching now, I added the close tab function after if it found the text

---------- Post updated at 12:30 PM ---------- Previous update was at 12:05 PM ----------

The site will only display 300 records at a time, so I have to click the next page button every 300 pages. It has searched 500 pages so far. How could I add a click next page after its done searching the first page. And maybe a save as pdf or Web archive when it finds one that has "text"