使用Headless FireFox在Linux中使用命令行保存所有HTML文件

use*_*418 9 shell firefox headless

使用shell_exec与Xvfb和FireFox当前捕获屏幕截图.但是,需要使用shell_exec将整个html(例如,将页面另存为 - >网页完成.)下载到目录.已经查看了Mozilla开发人员论坛中提供的所有不同选项,但未能弄清楚如何执行此操作.

这段代码似乎是我可能需要的,但是在哪里以及如何实现它以便可以在shell_exec中访问它?

var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("C:\\filename.html");
var wbp = Components.classes['@mozilla.org/embedding/browser/nsWebBrowserPersist;1']
.createInstance(Components.interfaces.nsIWebBrowserPersist);
wbp.saveDocument(content.document, file, null, null, null, null);
Run Code Online (Sandbox Code Playgroud)

以上代码来源

void saveDocument(
in nsIDOMDocument aDocument,
in nsISupports aFile,
in nsISupports aDataPath,
in string aOutputContentType,
in unsigned long aEncodingFlags,
in unsigned long aWrapColumn
);
Run Code Online (Sandbox Code Playgroud)

以上代码来源

这里有一个Stackoverflow手动解决方案,但它没有解决shell_exec: 如何在本地保存网页,包括图片等

ani*_*ane 1

我知道的选项很少,但我知道没有一个选项完全适合您的问题。

  1. 从 shell打开firefox http://yoursite.com,然后使用或类似的方法将击键发送到 firefox xte。(但这不是无头模式。)
  2. 使用 wget 下载。它可以以递归方式工作。或者,如果是非常简单的网页,您也可以解析 HTML。如果需要提交表单,请使用curl而不是wget。
  3. 使用greasemonkey插件并编写一个脚本,该脚本将被加载http://some-fake-page.com/?download=http://yoursite.com,然后使用该假页面url打开firefox。
  4. 开发您自己的 Firefox 插件来完成上述工作。

可能还有其他更好的选择,但我不知道。