save html output of page after execution of the page's javascript

后端 未结 7 957
情话喂你
情话喂你 2020-11-29 21:12

There is a site I am trying to scrape, that first loads an html/js modifies the form input fields using js and then POSTs. How can I get the final html output of the POSTed

7条回答
  •  暖寄归人
    2020-11-29 21:36

    I'm using CasperJS to run tests with PhantomJS. I added this code to my tearDown function:

    var require = patchRequire(require);
    var fs = require('fs');
    
    casper.test.begin("My Test", {
        tearDown: function(){
            casper.capture("export.png");
            fs.write("1.html", casper.getHTML(undefined, true), 'w');
        },
        test: function(test){
            // test code
    
            casper.run(function(){
                test.done();
            });
        }
    });
    

    See docs for capture and getHTML.

提交回复
热议问题