【发布时间】:2019-12-26 19:36:23
【问题描述】:
我正在尝试寻找一种方法来获取/下载website。
我尝试了wget 和curl 但没有成功,然后我被引导到PhantomJS。
var url = 'https://www.sagedining.com/menus/admiralfarragutacademy';
var fs = require('fs');
var page = require('webpage').create();
page.open(url, function(status) {
if (status === 'success') {
var html = page.evaluate(function() {
return document.documentElement.outerHTML;
});
try {
fs.write("/root/choate/page.html", html, 'w');
} catch(e) {
console.log(e);
}
}
phantom.exit();
});
当我在我的 Debian VPS 上运行此代码时,
sudo xvfb-run -- phantomjs menu.js
它会在网站仍在加载时下载该网站,因此只下载加载屏幕。 每次运行时也会抛出这个错误:
TypeError: Attempting to change the setter of an unconfigurable property.
TypeError: Attempting to change the setter of an unconfigurable property.
在加载所有菜单后,有什么方法可以下载这个网站?报错信息和它有关系吗?
提前谢谢你。
【问题讨论】:
-
我不熟悉 phantomjs,但你为什么不等待几秒钟
setTimeout,以确保 web 已加载?类似于主要示例:phantomjs.org,如果您不想等待固定秒数,您可以使用setInterval检查页面数据是否已完全加载。
标签: javascript curl phantomjs wget