在 Cocoa 中保存 Webarchive 而不使用图像

发布于 2024-10-10 19:51:55 字数 401 浏览 10 评论 0原文

我有一个 WebView,我想将其保存为 WebArchive。我只想保存 HTML 部分而不是引用的图像。当我执行以下操作时,它似乎正在创建一个也嵌入图像的 WebArchive。

[[[[[sourceSignatureWebView mainFrame] dataSource] webArchive] data]
  writeToFile:@"MyWebarchive.webarchive" atomically:YES];

除了我不想嵌入图像之外,Safari 似乎在显示文件时遇到了问题,并且在我想要的 HTML 部分周围显示了大量二进制乱码。我知道我可以使用 textutil 来创建文件,但如果可能的话我想在 Cocoa 中完成这一切。

有谁知道这是否可行?任何想法将不胜感激。谢谢!

I have a WebView that I want to save as a WebArchive. I just want to save the HTML part and not the referenced images. When I do the following, it appears to be creating a WebArchive with the images embedded as well.

[[[[[sourceSignatureWebView mainFrame] dataSource] webArchive] data]
  writeToFile:@"MyWebarchive.webarchive" atomically:YES];

Besides the fact that I don't want to embed the images, Safari seems to have trouble displaying the file and is showing a lot of binary gibberish wrapped around the HTML part I want. I know I can use textutil to create the file, but if possible would like to do it all inside Cocoa.

Does anyone know if this is doable? Any ideas would be much appreciated. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最丧也最甜 2024-10-17 19:51:55

像这样的事情怎么样:

WebDataSource *dataSource = [[sourceSignatureWebView mainFrame] dataSource];

WebArchive *archive = [[WebArchive alloc]
                       initWithMainResource:[dataSource mainResource]
                       subresources:nil
                       subframeArchives:nil];

[[archive data] writeToURL…

或者您实际上是在寻找 HTML 文件而不是 Web 存档?

How about something like this:

WebDataSource *dataSource = [[sourceSignatureWebView mainFrame] dataSource];

WebArchive *archive = [[WebArchive alloc]
                       initWithMainResource:[dataSource mainResource]
                       subresources:nil
                       subframeArchives:nil];

[[archive data] writeToURL…

Or are you actually after an HTML file rather than web archive?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文