admin管理员组文章数量:1026989
I am building an add-on for an application. The clients are paying to view some webpages and download some files out of it. They want to automate this downloading process by add-on. So instead of selecting "Save Page as" and waiting for the download's pletion, they can click the add-on and forget the process. The problem is, the webpage is providing some cookies to the browser. So the best way is File-> "Save Page As" . I want to do it through the add-on. Is there any firefox-javascript way for this?. I used nsiDownloader. But it saves only html, not the pictures,etc. Can anybody guide me in this issue?
EDIT: Hi, This is the code which did the trick, thanks to sai prasad
var dir =Components.classes["@mozilla/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
dir.initWithPath("C:\\filename");
var file = Components.classes["@mozilla/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("C:\\filename.html");
var wbp = Components.classes['@mozilla/embedding/browser/nsWebBrowserPersist;1']
.createInstance(Components.interfaces.nsIWebBrowserPersist);
alert("going to save");
wbp.saveDocument(content.document, file,dir, null, null, null);
alert("saved");
EDIT: But, still some webpages are not saved exactly as "Save Page as". Those saved pages are not rendered like original pages, they are look like some html example.
I am building an add-on for an application. The clients are paying to view some webpages and download some files out of it. They want to automate this downloading process by add-on. So instead of selecting "Save Page as" and waiting for the download's pletion, they can click the add-on and forget the process. The problem is, the webpage is providing some cookies to the browser. So the best way is File-> "Save Page As" . I want to do it through the add-on. Is there any firefox-javascript way for this?. I used nsiDownloader. But it saves only html, not the pictures,etc. Can anybody guide me in this issue?
EDIT: Hi, This is the code which did the trick, thanks to sai prasad
var dir =Components.classes["@mozilla/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
dir.initWithPath("C:\\filename");
var file = Components.classes["@mozilla/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("C:\\filename.html");
var wbp = Components.classes['@mozilla/embedding/browser/nsWebBrowserPersist;1']
.createInstance(Components.interfaces.nsIWebBrowserPersist);
alert("going to save");
wbp.saveDocument(content.document, file,dir, null, null, null);
alert("saved");
EDIT: But, still some webpages are not saved exactly as "Save Page as". Those saved pages are not rendered like original pages, they are look like some html example.
Share Improve this question edited Jul 1, 2012 at 14:01 prabhakaran asked Jun 30, 2012 at 6:07 prabhakaranprabhakaran 5,27417 gold badges75 silver badges109 bronze badges 1- I'm not really 100% on this but take a look at CURL – Sturm Commented Jun 30, 2012 at 7:38
1 Answer
Reset to default 5Since you mention that File->"Save Page As" is working as expected, I tried looking through the source code (chrome://browser/content/browser.xul) and found this:
https://developer.mozilla/en/nsIWebBrowserPersist#saveDocument()
Make sure that you shall call this function only after the webpage is pletely loaded (not DOMContentLoaded)!!
I am building an add-on for an application. The clients are paying to view some webpages and download some files out of it. They want to automate this downloading process by add-on. So instead of selecting "Save Page as" and waiting for the download's pletion, they can click the add-on and forget the process. The problem is, the webpage is providing some cookies to the browser. So the best way is File-> "Save Page As" . I want to do it through the add-on. Is there any firefox-javascript way for this?. I used nsiDownloader. But it saves only html, not the pictures,etc. Can anybody guide me in this issue?
EDIT: Hi, This is the code which did the trick, thanks to sai prasad
var dir =Components.classes["@mozilla/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
dir.initWithPath("C:\\filename");
var file = Components.classes["@mozilla/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("C:\\filename.html");
var wbp = Components.classes['@mozilla/embedding/browser/nsWebBrowserPersist;1']
.createInstance(Components.interfaces.nsIWebBrowserPersist);
alert("going to save");
wbp.saveDocument(content.document, file,dir, null, null, null);
alert("saved");
EDIT: But, still some webpages are not saved exactly as "Save Page as". Those saved pages are not rendered like original pages, they are look like some html example.
I am building an add-on for an application. The clients are paying to view some webpages and download some files out of it. They want to automate this downloading process by add-on. So instead of selecting "Save Page as" and waiting for the download's pletion, they can click the add-on and forget the process. The problem is, the webpage is providing some cookies to the browser. So the best way is File-> "Save Page As" . I want to do it through the add-on. Is there any firefox-javascript way for this?. I used nsiDownloader. But it saves only html, not the pictures,etc. Can anybody guide me in this issue?
EDIT: Hi, This is the code which did the trick, thanks to sai prasad
var dir =Components.classes["@mozilla/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
dir.initWithPath("C:\\filename");
var file = Components.classes["@mozilla/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("C:\\filename.html");
var wbp = Components.classes['@mozilla/embedding/browser/nsWebBrowserPersist;1']
.createInstance(Components.interfaces.nsIWebBrowserPersist);
alert("going to save");
wbp.saveDocument(content.document, file,dir, null, null, null);
alert("saved");
EDIT: But, still some webpages are not saved exactly as "Save Page as". Those saved pages are not rendered like original pages, they are look like some html example.
Share Improve this question edited Jul 1, 2012 at 14:01 prabhakaran asked Jun 30, 2012 at 6:07 prabhakaranprabhakaran 5,27417 gold badges75 silver badges109 bronze badges 1- I'm not really 100% on this but take a look at CURL – Sturm Commented Jun 30, 2012 at 7:38
1 Answer
Reset to default 5Since you mention that File->"Save Page As" is working as expected, I tried looking through the source code (chrome://browser/content/browser.xul) and found this:
https://developer.mozilla/en/nsIWebBrowserPersist#saveDocument()
Make sure that you shall call this function only after the webpage is pletely loaded (not DOMContentLoaded)!!
本文标签: javascriptHow to save a webpage locally including picturesetcStack Overflow
版权声明:本文标题:javascript - How to save a webpage locally including pictures,etc - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1741820743a1889866.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论