Search current webpage for phrase

Hi there, I'm trying to write an Apple script to search the currently open tab in Safari for 2 phrases, "free" & "bonus". I just want to search the parsed HTML, not the code itself. Any ideas how to do this?

Posted on Nov 17, 2015 2:21 AM

Reply
2 replies

Nov 17, 2015 3:49 AM in response to gribfromhonley

Something to get you started. Tested on El Capitan 10.11.1, using different keywords for tested website.


set word1 to "free"

set word2 to "bonus"


tell application "Safari"

activate

tell current tab of front window

set tabContent to text of it

if word1 is in tabContent and word2 is in tabContent then

display dialog "Found both " & word1 & " and " & word2

else if word1 is in tabContent then

display dialog "Found " & word1

else if word2 is in tabContent then

display dialog "Found " & word2

else

display dialog "Found neither " & word1 & " and " & word2

end if

end tell

end tell

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Search current webpage for phrase

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.