我想创建一个applescript。Applescript - 重新加载网页直到HTML包含特定文本
我需要在Chrome(或Safari)中自动重新加载当前网页,直到在HTML中出现一些特定的关键字。找到这个关键字后,停止重新加载。
该网页有一个带广告的区域。只要我能看到一些特定的广告,我就需要重新加载页面。这意味着关键字adPraha
在HTML中。
请问您能帮我吗?
set keyword to "adPraha"
tell application "Safari"
-- get the current window
set myWindow to (get current tab of window 1)
repeat
do JavaScript "window.location.reload()" in myWindow
-- wait for the page to load
repeat until ((do JavaScript "document.readyState;" in myWindow) is equal to "complete")
delay 0.5
end repeat
set pageContent to text of myWindow
if pageContent contains keyword then
else
end if
delay 2 -- wait a bit before running again
end repeat
end tell
这个脚本究竟有什么问题?它似乎对我有用。我在'else/end if'之间添加了'if/else'和另一个之间的显示对话框,并且当'pageContent'包含'keyword'时成功检测到脚本。你在寻找'exit repeat'命令吗?将它放在'else/endif'之间,或者将“contains keyword”替换为“不包含关键字”,它会在丢失关键字时退出重复。 –