简体   繁体   中英

Periodically save Generated HTML to local file

OK, so this what I'm trying to do - and I'm open to suggestions.

  • I open up a webpage (in Chrome/Firefox - doesn't matter)
  • The webpage contains self-updating AJAX, which means the generated html/dom changes like every minute
  • I want to be able to automatically (no save as , no nothing) save the source locally

How can this be done?


PS I've been playing with the .js console, firebug, etc. But I'm still not sure how to go about this. So any suggestion is more than welcome! :-)

You can use this snippet to save the HTML source on HD using JS, here document.documentElement.outerHTML is used to get the HTML source for the page:-

<HTML>
<HEAD>
<script LANGUAGE="JavaScript">
    function SaveToDisk(sPath)
    {
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        var fileDest = fso.CreateTextFile(sPath, true);
        if (fileDest)
        {
           fileDest.Write(document.documentElement.outerHTML);
           fileDest.close();
        }
        else
        {
           alert("unable to create file " + sPath);
        }

    }        
</script>
</HEAD>

<BODY onload="SaveToDisk('c:\\temp\\123.htm');">
<P>The rest of the page is here...</P>
</BODY>
</HTML>

There is also a solution available where you can save source for another website by providing the url , check this

For chrome, open the js console and enter:

window.open('data:text/html;charset=utf-8,' + escape(document.documentElement.outerHTML));

Then you can save the generated html. It may also work in other browsers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM