How can i export html to file via command line with FireFox

So the question explains itself very good.

Is there a console command line to save the html with firefox?

Thanks.


Solution 1:

There is no way to ask Firefox to save a page via command line (as of May 2015). There is, however, a script that can automate the process of launching Firefox, saving the page, quitting Firefox.

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

From the README file:

A quick hack for when wget doesn't cut it.

tl;dr Perform browser's "Save page as" (Ctrl+S) operation from command line without manual intervention

This small bash script simulates a sequence of key presses which opens a given url in the browser, save the page (Ctrl+S), and close the browser tab/window (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" 

Solution 2:

The suggestion to use wget wouldn't handle the case where access to the content requires special login or other authentication that requires some user action from inside the browser (e.g. storing the authentication results for example in firefox's cert8.db or keys.db or signons.sqlite or even in locatsore.rdf). wget --load-cookies using the firefox cookies may not work, if authentication is done via javascript inside the web page loaded.

So the user want some way to run firefox like so:

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

(and firefox exits when it has finished saving the URL it fetched). Yes, it's heavy, but if you can view the page in a browser but not via wget or similar, then there doesn't currently seem to be any way to do it that could be used from the command line.

However, it may simply be that the user did not export the freshest cookies file from FF so that it could be loaded by wget --load-cookies, since to create a wget-compatible (netscape style) cookies file requires: 1) installing a plugin like Export Cookies 2) exporting the cookies.txt file for wget to use.

Solution 3:

Use pup. Unlike automate-save-page-as, pup doesn't save the raw HTML, but outputs the parsed HTML.