要从网站获取信息,你可以使用AppleScript的网络访问功能。以下是一个示例代码,演示了如何使用AppleScript从网站获取信息:
-- 设置要访问的网站URL
set websiteURL to "https://example.com"
-- 使用AppleScript的“do shell script”命令执行cURL命令来获取网页内容
set shellScript to "curl " & websiteURL & " 2>/dev/null"
set websiteContent to do shell script shellScript
-- 处理网页内容
-- 例如,你可以将网页内容保存到文件
set savePath to (path to desktop as string) & "websiteContent.txt"
try
set fileHandle to open for access file savePath with write permission
write websiteContent to fileHandle
close access fileHandle
display dialog "网页内容已保存到桌面上的websiteContent.txt文件中。"
on error errMsg
display dialog "保存文件时出错:" & errMsg
try
close access file savePath
end try
end try
上述代码将网页内容保存到桌面上的名为"websiteContent.txt"的文件中。你可以根据自己的需求进行修改和扩展。请确保你已安装cURL工具,因为它是执行网络请求的关键。