AppleScript:如何一次循环一个 URL 列表以打开和打开关闭浏览器窗口

发布于 2024-12-09 11:19:10 字数 803 浏览 0 评论 0原文

我正在尝试在浏览器中一次加载一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜味拾荒者 2024-12-16 11:19:10

这会设置一个 URL 列表,加载每个 URL,然后等待文档准备好继续。请注意,每个 URL 都必须完整(即 http://cnn.com/ 而不是 cnn.com)才能以这种方式加载页面。

set myURLs to {"http://stackoverflow.com/", "http://cnn.com/", "http://nytimes.com/"}

tell application "Safari"
    make new document
    set myDoc to front document
    repeat with myURL in myURLs
        set URL of myDoc to myURL
        -- wait until page is loaded to open new page
        repeat until ((do JavaScript "document.readyState" in front document) is "complete")
            delay 1
        end repeat
    end repeat
end tell

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 not cnn.com) to load a page this way.

set myURLs to {"http://stackoverflow.com/", "http://cnn.com/", "http://nytimes.com/"}

tell application "Safari"
    make new document
    set myDoc to front document
    repeat with myURL in myURLs
        set URL of myDoc to myURL
        -- wait until page is loaded to open new page
        repeat until ((do JavaScript "document.readyState" in front document) is "complete")
            delay 1
        end repeat
    end repeat
end tell
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文