某个远程服务器上有一个 XML 文件(http://foo/bar.xml):
<?xml version="1.0" encoding="UTF-8"?>
<foo>
bar
</foo>
如何使用 AppleScript 获取值“bar”?
最佳答案
这是我所做的:
set file_tgt to (POSIX path of (path to temporary items)) & "file.xml"
do shell script "curl -L " & "http://url.com/file.xml" & " -o " & file_tgt
tell application "System Events"
set file_content to contents of XML file file_tgt
tell file_content
set my_value to value of XML element 1
end tell
end tell
最初我使用“URL 访问脚本”应用程序来获取文件,但由于它已在 Lion 中删除,我切换到纯 curl,它在 Snow Leopard 和 Lion 下都可以使用。
关于applescript - 如何使用 AppleScript 获取和解析 XML 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7280362/