AppleScript读取和保存网站内容(API)

时间:2012-11-26 17:33:20

标签: url safari applescript

我有一个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=Avatar&y=2009

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

有人可以帮忙吗?

1 个答案:

答案 0 :(得分: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
相关问题