Google Групи більше не підтримують нові дописи або підписки Usenet. Наявний контент можна переглядати.

How to do a File/Save Page As

11 переглядів
Перейти до першого непрочитаного повідомлення

shi...@gmail.com

не прочитано,
23 лист. 2006 р., 23:53:5623.11.06
Кому:
I'm trying to get Firefox to auto-save certain pages for me to a
specific directory. I mostly have it working by using the following
code snippet (which I found in another extension):

var filename = "path to non-existent file";
var file =
Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(filename);

// initialize the downloader
var persist =
Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].

createInstance(Components.interfaces.nsIWebBrowserPersist);

var tmpIWBP = Components.interfaces.nsIWebBrowserPersist;

persist.persistFlags = tmpIWBP.PERSIST_FLAGS_FROM_CACHE |
tmpIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES
|

tmpIWBP.PERSIST_FLAGS_NO_BASE_TAG_MODIFICATIONS |
tmpIWBP.PERSIST_FLAGS_DONT_FIXUP_LINKS |
tmpIWBP.PERSIST_FLAGS_DONT_CHANGE_FILENAMES
|
tmpIWBP.PERSIST_FLAGS_NO_CONVERSION;

var encode = tmpIWBP.ENCODE_FLAGS_RAW;
persist.saveDocument(aDoc, file, null, null, encode, 0);


This *mostly* works. I do get a file, but the actual contents is
different from File/Save Page As (Web Page, HTML only). For instance,
this code ends up using " rather than ' for attributes and javascript.
Also I see <tbody> tags rather than <body>.

I would really like to duplicate the same file format is File/Save Page
As. Do I just need to use different pesistFlags? Maybe access the
content directly, create a text file, and drop the content in? If so,
any pointers on how to grab that content and create a text file?

Thanks!

0 нових повідомлень