AppleScript:如何一次循环一个 URL 列表以打开和打开关闭浏览器窗口
我正在尝试在浏览器中一次加载一个 URL 列表。我不关心任何输出,我只需要加载页面,完全加载完成后,将位置更改为列表中的下一个 URL。我尝试过并放弃在 Automator 中完成此任务。我会使用 CURL,但我对通过身份验证了解不够(必须存在多个 cookie)。
这可以通过简单的 ActionScript 实现吗?理想情况下,输入是一个 txt 文件,每个 URL 对应一行。
更新!这是有效的:
set thePath to (path to desktop as Unicode text) & "sites.txt"
set theFile to (open for access file thePath)
set theContent to (read theFile)
close access theFile
set theURLs to every paragraph of theContent
tell application "Safari"
repeat with theURL in theURLs
make new document
set URL of front document to theURL
delay 1
repeat until ((do JavaScript "document.readyState" in front document) is "complete")
delay 1
end repeat
close front document
end repeat
end tell
I'm trying to load a list of URLs in a browser one at a time. I don't care about any output, I just need the page to load, once finished loading completely, change the location to the next URL in the list. I've tried and given up accomplishing this in Automator. I'd use CURL but I don't know enough about passing authentication (several cookies must be present).
Is this possible with a simple ActionScript? Ideally, input would be a txt file with a line for each URL.
Update! This is working:
set thePath to (path to desktop as Unicode text) & "sites.txt"
set theFile to (open for access file thePath)
set theContent to (read theFile)
close access theFile
set theURLs to every paragraph of theContent
tell application "Safari"
repeat with theURL in theURLs
make new document
set URL of front document to theURL
delay 1
repeat until ((do JavaScript "document.readyState" in front document) is "complete")
delay 1
end repeat
close front document
end repeat
end tell
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这会设置一个 URL 列表,加载每个 URL,然后等待文档准备好继续。请注意,每个 URL 都必须完整(即
http://cnn.com/
而不是cnn.com
)才能以这种方式加载页面。This sets a list of URLs, loads each one, and waits until the document is ready to continue. Note that each URL has to be complete (i.e.,
http://cnn.com/
and notcnn.com
) to load a page this way.