如何使用 Apple 脚本阅读 HTML post 的答案
How do I read the answer of a HTML post with Apple script
如何在使用 applescript 时从 this, this or this link 中读取某些值。
我需要帮助从服务器获取答案以及阅读 JSON、XML、HTML 响应(乘法 links 的原因)
如果有人能指出任何体面的文档,那也很好
以下是在 XML 和 JSON 版本中获取 "city" 值的方法。请注意,您必须将 JSON 转换为 PLIST 才能允许 AppleScript 解析它。它们是高度兼容的格式,因此转换应该可以完美地进行。您可以通过将 HTML 版本视为 XML 来解析它,但这通常不是一个好主意。它不是为数据提取而设计的,很容易失败。
--XML version
tell application "System Events"
set weather_XML to make XML data with properties ¬
{id:"WeatherXML", name:"WeatherXML", text:(do shell script "curl 'http://api.openweathermap.org/data/2.5/weather?q=London&mode=xml&appid=2de143494c0b295cca9337e1e96b00e0'")}
get value of XML attribute "name" of XML element "city" of XML element "current" of weather_XML
quit
end tell
--JSON version. Note the "plutil" conversion.
tell application "System Events"
set weather_PLIST to make property list item with properties ¬
{name:"WeatherPLIST", text:(do shell script "curl 'http://api.openweathermap.org/data/2.5/weather?q=London&mode=json&appid=2de143494c0b295cca9337e1e96b00e0'|plutil -convert xml1 - -o -")}
get value of property list item "name" of weather_PLIST
quit
end tell
您可以在系统事件词典中阅读更多相关信息,可以通过键入 ⌘+shift+[=15 来访问=]o 在脚本编辑器中,然后从列表中选择 "System Events.app"。
如何在使用 applescript 时从 this, this or this link 中读取某些值。
我需要帮助从服务器获取答案以及阅读 JSON、XML、HTML 响应(乘法 links 的原因)
如果有人能指出任何体面的文档,那也很好
以下是在 XML 和 JSON 版本中获取 "city" 值的方法。请注意,您必须将 JSON 转换为 PLIST 才能允许 AppleScript 解析它。它们是高度兼容的格式,因此转换应该可以完美地进行。您可以通过将 HTML 版本视为 XML 来解析它,但这通常不是一个好主意。它不是为数据提取而设计的,很容易失败。
--XML version
tell application "System Events"
set weather_XML to make XML data with properties ¬
{id:"WeatherXML", name:"WeatherXML", text:(do shell script "curl 'http://api.openweathermap.org/data/2.5/weather?q=London&mode=xml&appid=2de143494c0b295cca9337e1e96b00e0'")}
get value of XML attribute "name" of XML element "city" of XML element "current" of weather_XML
quit
end tell
--JSON version. Note the "plutil" conversion.
tell application "System Events"
set weather_PLIST to make property list item with properties ¬
{name:"WeatherPLIST", text:(do shell script "curl 'http://api.openweathermap.org/data/2.5/weather?q=London&mode=json&appid=2de143494c0b295cca9337e1e96b00e0'|plutil -convert xml1 - -o -")}
get value of property list item "name" of weather_PLIST
quit
end tell
您可以在系统事件词典中阅读更多相关信息,可以通过键入 ⌘+shift+[=15 来访问=]o 在脚本编辑器中,然后从列表中选择 "System Events.app"。