加载网页,执行其 JavaScript 并将生成的 HTML 转储到文件
我需要加载一个网页,执行其 JavaScript(以及标签中包含的所有 js 文件)并将生成的 HTLM 转储到文件中。这需要在服务器上完成。我已经尝试过使用node.js和zombie.js,但它似乎太不成熟,无法在现实世界中工作。通常,它只是抛出一个虚假的异常,而真正的浏览器(FireFox)则没有页面问题。
我的node.js 代码是:
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);
}
});
它退出时出现异常“TypeError: Cannot call method 'toString' of null”
Jaxer 并不是真正的选项。我需要下载第 3 方页面并在我的服务器上执行它。我该如何与 Jaxer 一起做呢?
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许这是因为您正在使用
err.message
而err
未定义?另一方面,错误
已定义。更新
您查看过PhantomJS吗?
另外,看起来 Aptana Jaxer 可以做你想做的事。引用John Resig</a>:
Perhaps that’s because you are using
err.message
whereaserr
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: