safari - Applescript:Safari 无法保存网页(AppleEvent 处理程序失败错误)

标签 safari applescript web-crawler appleevents

我希望 Safari 使用 Apple automator 下载并保存网页。打开 Safari 窗口后,我在 AppleScript 编辑器中运行以下脚本:

tell application "Safari"
    set URL of document 1 to "http://www.python.org"
    delay 6
    get document 1
    delay 6
    save document 1 in "/mydir/" & "python" & ".htm"
end tell

Safari 显示正确的 url,但随后我在 safari 中收到以下错误:

“文档“Python编程语言-官网”无法保存为“python.htm”。”

我在该错误框上单击“确定”,然后 AppleScript 编辑器在对话框中给我这个错误:

“AppleScript 错误
Safari 出现错误:AppleEvent 处理程序失败。”

AppleScript 编辑器底部有一个名为“结果”的框,它还显示以下消息:

“错误”Safari 出现错误:AppleEvent 处理程序失败。“数字 -10000”

并且网页不会保存。我不知道是什么导致了这个 b/c 我 99% 确定我过去使用过相同(或相似)的代码来保存页面。

奇怪的是,我将“get document 1”和“save document 1”行移到“tell application safari” block 之外,并将applescript保存为“python.htm”,当用Firefox打开时,它看起来很傻。所以问题似乎是Safari无法保存而不是osx。

此外,我使用 chmod 将目标保存目录的所有权限更改为 all(在 bash 中使用 777 参数)。

我更新了软件重启了几次。

这是我的版本:

Safari:版本 5.1 (6534.50)
OSX 雪豹:版本 10.6.8
苹果脚本 2.1.2
AppleScript 编辑器:版本 2.3 (118)
我被束缚在手机上,将其用作移动接入点。我不知道这是否重要。

我认为这个人有同样的错误,但没有答案:

Why does this AppleScript get an "AppleEvent handler failed" error on Mac OS X 10.5 Leopard?

有人猜到了吗?谢谢。

最佳答案

我不知道真正的答案,但它有 50 多个 View 和风滚草,所以我想我会发布一些东西。

显然你应该使用 curl:

tell application "Safari"
    set URL of document 1 to "http://www.python.org"
    delay 6
    get document 1
    set my_html to URL of document 1
end tell

set my_new_file to "/Users/your_user_name/python.htm"
set my_script to "curl " & my_html & " >> " & my_new_file

do shell script my_script

(我在 macscripter 上看到了一篇帖子,他们说这是“唯一的方法”,所以可能无法在 Safari 中使用“另存为”,这是一个常见的 applescript 错误,但没有得到答复 b/c 这是不是applescript板?无论如何,也许原始帖子应该可以工作,但我只是不知道更好。我想如果人们在板上或通过谷歌找到这个,答案可能会有所帮助,或者模组只是想要如果这是一个明显的解决方案,请将其删除)。

关于safari - Applescript:Safari 无法保存网页(AppleEvent 处理程序失败错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6932656/

相关文章:

ios - Facebook 请求通知未显示在 iOS 移动版 safari 中,而是显示在 native facebook 应用程序中

javascript - 强制 safari iOS 选择组件在选项更改时更新

Python:BeautifulSoup 返回垃圾

css - Flex 自动边距在 Chrome 和 Safari 中的行为不同

html - 单击 UIWebView 时如何在 Safari 中打开链接?

cocoa - 在 cocoa 中集成 applescript

cocoa - 使用参数从 Cocoa App 执行 Applescript

macos - Applescript 将启动 Chrome(具体内容)

python - 如何从Playstore中的应用程序获取权限信息?

web-crawler - 抓取网页有限制