1

我有一个 AppleScript 可以逐行读取 URL 并在 Safari 中打开它们。这个:

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 30
        end repeat
        close front document
    end repeat
end tell

在此示例中,我使用这些 URL - 它们与我的用例非常相似,我无法分享。

http://www.omdbapi.com/?t=True%20Grit&y=1969

http://www.omdbapi.com/?t=阿凡达&y=2009

这个 AppleScript 对我来说很好用,但我无法将内容写回桌面上的 txt 文件,按请求请求。

有人可以帮忙吗?

4

1 回答 1

0

尝试:

set thePath to (path to desktop as text) & "sites.txt"
set outPath to quoted form of (POSIX path of (path to desktop as text) & "sites content.txt")

set theUrls to every paragraph of (read file thePath)

set myContent to {}
repeat with aURL in theUrls
    set end of myContent to aURL & return
    set pageContent to do shell script "curl " & aURL
    set end of myContent to pageContent & return & return
end repeat

do shell script "echo " & quoted form of (myContent as text) & " >> " & outPath
于 2012-11-26T18:33:39.727 回答