Load a web page, execute its JavaScript and dump resulting HTML to a file

ぃ、小莉子 提交于 2019-12-20 02:36:13

问题


I need to load a web page, execute its JavaScript (and all js files included with the tags) and dump resulting HTLM to a file. This needs to be done on the server. I have tried node.js with zombie.js but it seems it is too immature to work in the real world. More often than not it just throws a bogus exception while a real browser (FireFox) has no issues with the page.

My node.js code is:

var zombie = require("zombie"),
    sys = require('sys');

// Load the page
var browser = new zombie.Browser({ debug: false });
browser.visit('http://www.dba.dk', function (error, browser, status) {
    if (error) { console.log('Error:' + error.message); }
    if (!error && browser.statusCode == 200) {
        sys.puts(browser.html);
    }
});

and it exits with an exception "TypeError: Cannot call method 'toString' of null"

Jaxer is not really an option.. I need to download a 3rd party page and execute it on my server. How would I do that with Jaxer


回答1:


Perhaps that’s because you are using err.message whereas err is not defined? error, on the other hand, is defined.


Update

Did you check out PhantomJS?

Also, it looks like Aptana Jaxer could do what you want. To quote John Resig:

Imagine ripping off the visual rendering part of Firefox and replacing it with a hook to Apache instead - roughly speaking that's what Jaxer is.



来源:https://stackoverflow.com/questions/5392532/load-a-web-page-execute-its-javascript-and-dump-resulting-html-to-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!