【发布时间】:2017-07-01 11:31:24
【问题描述】:
我想创建一个applescript。
我需要在 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
【问题讨论】:
-
这个脚本到底有什么问题?对我来说,它似乎有效。我在
if/else和else/end if之间添加了一个显示对话框,当pageContent包含keyword时脚本成功检测到。您在寻找exit repeat命令吗?把它放在else/endif之间或将“包含关键字”替换为“不包含关键字”,它会在关键字丢失时退出重复。
标签: html search applescript reload