如何通过命令行使用FireFox将html导出到文件

时间:2013-03-15 10:18:43

标签: firefox command-line

所以问题解释得非常好。

是否有控制台命令行用firefox保存html?

感谢。

3 个答案:

答案 0 :(得分:11)

使用wget的建议不会处理访问内容需要特殊登录或需要在浏览器内部进行某些用户操作的其他身份验证的情况(例如,将验证结果存储在firefox的cert8.db或密钥中)。 db或signons.sqlite,甚至是locatsore.rdf)。使用firefox cookie的wget --load-cookies可能无效,如果通过加载的网页内的javascript进行身份验证。

因此用户想要某种方式来运行firefox,如下所示:

firefox "<some-url-with-complex-authentication>" -save-to-folder ./somewhere

(当firefox完成保存所获取的URL时退出)。 是的,它很重,但如果您可以在浏览器中查看页面而不是通过wget或类似页面,那么目前似乎没有任何方法可以从命令行使用它。

但是,可能只是用户没有从FF导出最新的cookie文件,因此可以通过wget -load-cookies加载,因为创建一个兼容wget的(netscape样式)cookie文件需要: 1)安装Export Cookies这样的插件 2)导出cookies.txt文件供wget使用。

答案 1 :(得分:11)

无法让Firefox通过命令行保存页面(截至2015年5月)。但是,有一个脚本可以自动启动Firefox,保存页面,退出Firefox。

https://github.com/abiyani/automate-save-page-as

来自README文件:

  

当wget没有削减它时快速破解。

     

tl; dr执行浏览器&#34;将页面保存为&#34; (Ctrl + S)从命令行进行操作,无需人工干预

     

这个小bash脚本模拟一系列按键,在浏览器中打开一个给定的URL,保存页面(Ctrl + S),然后关闭浏览器选项卡/窗口(Ctrl + F4)。

# Use Firefox to open a web-page and save it in /tmp
# (the default name for the file (Page title) is used)
$ ./save_page_as "www.example.com" --browser "firefox" --destination "/tmp" 

答案 2 :(得分:1)

使用pup。与automate-save-page-as不同,pup不会保存原始HTML,而是输出已解析的HTML。

相关问题